- Subhasish Mishra
Python tutorial for beginners in Hindi-Chapter 11(String handling)
अपडेट किया गया: 10 नव. 2020
String
String collections का एक संग्रह है जो '', "", "" "", "" "" "" में संलग्न हैं।
' ' और " " का उपयोग single-line string के लिए किया जाता है।
" " " " और " " " " " " multiline string के लिए उपयोग किया जाता है।
String अपरिवर्तनीय है इसका मतलब है कि हम एक स्ट्रिंग पर modification नहीं कर सकते हैं।
String elements को access करने के लिए हम index का उपयोग करते हैं।
String positive और negative index की अनुमति देता है।
String + ,* और :(slice) ऑपरेटरों का अनुमति देता है ।

s = "Python"
print(s) #Python
print(s[0]) #P
print(s[-1]) #n
s[2] = a #Error (no modification)
Example of multiline string
s1 ="'This is
python tutorial
by hindi technocard'"
print(s1[5]) #i
Example of ' ' and " "
print("python") #python
print("'python'") #'python'
python('"pyrhon"') #"python"
Example on + operator
+ ऑपरेटर दो strings को concat करके एक नया string return करेगा।
s1 = "Python"
s2 = "Tutoril"
s3 =s1 +s2
print(s3) #PythonTutorial
Example on * operator
* ऑपरेटर string को दिए गए number से multiply करेगा और एक नया string प्रदान करेगा।
s1 ="Python"
s2 = s1 * 2
print(s2) #PythonPython
Example on slice(:) operator
s1 = "Python Tutorial by Hindi Techno Card"
print(s1[0:8]) #Python T
print(s1[0:8:2]) #Pto
String class method
capitalize():- Converts the first character to upper case
count():- Returns the number of times a specified value occurs in a string
encode():- Returns an encoded version of the string
endswith():- Returns true if the string ends with the specified value
index():- Searches the string for a specified value and returns the position of where it was found
lower():- Converts a string into lower case
और बी बोहत सरे methods है जिसे आप जान सकते हैं।
आज के इस चैप्टर में हम string के बारे में पढ़ा। अगले chapter में set के बारे में पढ़ेंगे। अगर आप chapter wise notes चाहते हैं तो comment में आप ईमेल डालिये।