Python string with example in tamil


இந்த கட்டுரையில் , Python string மற்றும் அதன் அடிப்படை செயல்பாடுகள் பற்றி அறிந்து (python strings learn code operations) கொள்வீர்கள்.

Python-னில், சரம் (string) என்பது ஒற்றை மேற்கோள்கள் (' '), இரட்டை மேற்கோள்கள் (" "), அல்லது மூன்று மேற்கோள்கள் (''' ''' அல்லது """ """) ஆகியவற்றிற்குள் இணைக்கப்பட்ட எழுத்துக்களின் வரிசையாகும். உரைத் தரவைக் குறிக்க சரங்கள் பயன்படுத்தப்படுகின்றன, மேலும் எழுத்துக்கள் (letters), எண்கள் (numbers), குறியீடுகள் (symbols) மற்றும் சம இடைவெளி கொண்டிருக்கலாம்.

பைத்தானில் உள்ள சரங்களின் படிப்படியான விளக்கம்:


Creating a String:


மேற்கோள்களுக்குள் (quotes) உரையை இணைப்பதன் மூலம் நீங்கள் ஒரு string-யை உருவாக்கலாம்.



Python

my_string = "Hello, free seo tricks!"
another_string = 'This is a string.'

Triple quotes பயன்படுத்தி நீங்கள் Multiline strings உருவாக்கலாம்:


Python

multiline_string = '''This is a
multiline
string learn in free seo tricks.'''

Accessing Characters:


அட்டவணைப்படுத்தலைப் பயன்படுத்தி String தனிப்பட்ட எழுத்துக்களை அணுகலாம். Python '0' அடிப்படையிலான அட்டவணைப்படுத்தலைப் பயன்படுத்துகிறது, எனவே முதல் எழுத்து குறியீட்டு '0' இல் உள்ளது.



Python

my_string = "Free Seo Tricks!"
first_char = my_string[0]  
print(first_char)  # 'F'

How it's Works
Freeseotricks
0123456789101112
-13-12-11-10-9-8-7-6-5-4-3-2-1


String Length:


ஒரு சரத்தின் நீளத்தை (எழுத்துகளின் எண்ணிக்கை) கண்டுபிடிக்க, நீங்கள் len() செயல்பாட்டைப் பயன்படுத்தலாம்:

Python

my_string = "Free Seo Tricks.!"
length = len(my_string) 
print(length) # output : 17

Slicing Strings:


Slicing மூலம் ஒரு சரத்தின் String ஒரு பகுதியை நீங்கள் பிரித்தெடுக்கலாம். Colon (:) ஆபரேட்டரைப் பயன்படுத்தி slicing செய்யப்படுகிறது.

How it's Works
Free
seo
tricks
01234567891011121314
-15-14-13-12-11-10-9-8-7-6-5-4-3-2-1

Python

my_string = "Free Seo Tricks.!"
sliced_string = my_string[0:5]  
print(sliced_string) # "Free " with space also added.

How it's Works
Free
01234


Python

my_string = "Freeseotricks.!"
sliced_string = my_string[0:5]  
print(sliced_string) # "Frees" there is no space betweent the char. so 's' also added.

How it's Works
Freeseotricks
0123456789101112
-13-12-11-10-9-8-7-6-5-4-3-2-1

How it's Works
Frees
01234


தொடக்கம் அல்லது முடிவு குறியீட்டை முறையே தொடக்கம் அல்லது இறுதி வரை துண்டாகத் தவிர்க்கலாம்.

String Concatenation:


'+' ஆபரேட்டரைப் பயன்படுத்தி நீங்கள் சரங்களை இணைக்கலாம் (ஒருங்கிணைக்கலாம்):

Python

first_name = "free"
last_name = "seo tricks"
full_name = first_name + " " + last_name  # "free seo tricks"


String Methods:


பைதான் சரங்களை கையாள பல உள்ளமைக்கப்பட்ட முறைகளை வழங்குகிறது, அவை:

  • 'Upper()': சரத்தை பெரிய எழுத்தாக மாற்றுகிறது.
  • 'lower()': சரத்தை சிற்றெழுத்துக்கு மாற்றுகிறது.
  • 'strip()': முன்னணி மற்றும் பின்தங்கிய இடைவெளியை நீக்குகிறது.
  • 'replace()': ஒரு சப்ஸ்ட்ரிங்கை மற்றொரு சப்ஸ்ட்ரிங் கொண்டு மாற்றுகிறது.
  • 'split()': சரத்தை ஒரு பிரிப்பானின் அடிப்படையில் துணை சரங்களின் பட்டியலில் பிரிக்கிறது.
  • 'find()': துணைச்சரத்தின் முதல் நிகழ்வின் குறியீட்டைக் கண்டறியும்.
  • 'count()': ஒரு துணைச்சரத்தின் நிகழ்வுகளின் எண்ணிக்கையைக் கணக்கிடுகிறது.


Python

my_string = "Hello, World!"
upper_case = my_string.upper()  # "HELLO, WORLD!"


lower() : இந்த முறை ஒரு சரத்தில் உள்ள அனைத்து எழுத்துக்களையும் சிறிய எழுத்துக்கு மாற்றுகிறது.

Python

my_string = "FREE SEO TRICKS"
lowercase_string = my_string.lower()
print(lowercase_string)  # Output: "free seo tricks"

strip() : strip() முறையானது ஒரு string முன்னணி மற்றும் பின்தங்கிய இடைவெளியை (spaces, tabs, and newline characters) நீக்குகிறது .

Python

text = "   This is some text with extra spaces.   "
strip_text = text.strip()
print(strip_text)  # Output: "This is some text with extra spaces."

replace() : replace() முறையானது ஒரு குறிப்பிட்ட சப்ஸ்ட்ரிங்கின் அனைத்து நிகழ்வுகளையும் ஒரு string உள்ள மற்றொரு சப்ஸ்ட்ரிங் மூலம் மாற்றுகிறது.

Python

my_string = "Free seo tools"
new_string = my_string.replace("tools", "tricks")
print(new_string)  # Output: "Free seo tricks"

split() : split() முறையானது ஒரு string-யை ஒரு குறிப்பிட்ட டிலிமிட்டரின் அடிப்படையில் substrings பட்டியலாக உடைக்கிறது (list of substrings).

Python

sentence = "Free seo tricks is tamil a blog."
words = sentence.split()  # Split by whitespace
print(words)  # Output: ['Free', 'seo', 'tricks', 'is', 'tamil', 'a', 'blog.']

Python

csv_data = "chandra,kumar,30"
values = csv_data.split(',')
print(values)  # Output: ['chandra', 'kumar', '30']

Find() : Find() முறையானது ஒரு சரத்திற்குள் ஒரு குறிப்பிட்ட சப்ஸ்ட்ரிங்கைத் தேடுகிறது மற்றும் முதல் நிகழ்வின் குறியீட்டை வழங்குகிறது. சப்ஸ்ட்ரிங் கிடைக்கவில்லை என்றால், அது -1ஐத் தருகிறது.

How it's Works
Free
seo
tricks
01234567891011121314









^





Python

sentence = "Free seo tricks"
index = sentence.find("tricks")
print(index)  # Output: 9 (index of "tricks" in the string)

Python

sentence = "Free seo Tricks"
index = sentence.find("Tools")
print(index)  # Output: -1 (substring not found)

Count() : Count() முறையானது ஒரு சரத்திற்குள் ஒரு குறிப்பிட்ட சப்ஸ்ட்ரிங் நிகழ்வுகளின் எண்ணிக்கையைக் கணக்கிடுகிறது.

Python

sentence = "Free seo Tricks seo"
count = sentence.count("seo")
print(count)  # Output: 2 (count of "seo" in the string)

overlapping substrings:


Python

sentence = "aaaaaaa"
count = sentence.count("aa")
print(count)  # Output: 3 (count of "aa" in the string, overlapping)


String Formatting:


f-strings (வடிவமைக்கப்பட்ட சரம் எழுத்துக்கள்) அல்லது str.format() முறையைப் பயன்படுத்தி நீங்கள் சரங்களை வடிவமைக்கலாம்:

Python

name = "freeseotricks"
age = 30
formatted_string = f"My name is {name} and I am {age} years old."


Escape Characters:


சில எழுத்துகளுக்கு சரங்களில் சிறப்பு அர்த்தங்கள் உள்ளன, அதாவது '\n' ஒரு புதிய வரி அல்லது '\t' ஒரு தாவலுக்கு. இந்த எழுத்துக்களை ஒரு சரத்தில் சேர்க்க, நீங்கள் escape sequences பயன்படுத்தலாம்.

Python
message = "This is a new line.\nThis is a tab:\tTabbed text."


strings என்பது பைத்தானில் ஒரு அடிப்படை தரவு வகையாகும், are widely used in various applications, from simple text manipulation to complex data processing and manipulation. எந்த பைதான் புரோகிராமருக்கும் strings எவ்வாறு வேலை செய்வது என்பதைப் புரிந்துகொள்வது அவசியம்.



புதியது பழையவை