स्ट्रिंग ऑपरेशन

Python में Regular Expressions

Maria Eugenia Inzaugarat

Data Scientist

केस समायोजन

my_string = "tHis Is a niCe StriNg"
  • लोअरकेस में बदलना
print(my_string.lower())
this is a nice string
  • अपरकेस में बदलना
print(my_string.upper())
THIS IS A NICE STRING
Python में Regular Expressions

 

my_string = "tHis Is a niCe StriNg"

 

  • पहले अक्षर को कैपिटलाइज़ करना
print(my_string.capitalize())
This is a nice string
Python में Regular Expressions

स्प्लिट करना

my_string = "This string will be split"
  • स्ट्रिंग को सबस्ट्रिंग्स की लिस्ट में बाँटना
my_string.split(sep=" ", maxsplit=2)
['This', 'string', 'will be split']
my_string.rsplit(sep=" ", maxsplit=2)
['This string will', 'be', 'split']
Python में Regular Expressions

 

my_string = "This string will be split\nin two"

print(my_string)
This string will be split
in two

Python में Regular Expressions
  • लाइन बाउंड्री पर तोड़ना
my_string = "This string will be split\nin two"

 

my_string.splitlines()
['This string will be split', 'in two']
Python में Regular Expressions

जॉइन करना

  • लिस्ट या किसी और iterable की स्ट्रिंग्स को जोड़ना

 

my_list = ["this", "would", "be", "a", "string"]
print(" ".join(my_list))
this would be a string
Python में Regular Expressions

कैरेक्टर स्ट्रिप करना

  • बाएँ से दाएँ कैरेक्टर हटाएँ: .strip()

 

my_string = " This string will be stripped\n"
my_string.strip()
'This string will be stripped'
Python में Regular Expressions

 

my_string = " This string will be stripped\n"
  • दाएँ छोर से कैरेक्टर हटाएँ
my_string.rstrip()
' This string will be stripped'
  • बाएँ छोर से कैरेक्टर हटाएँ
my_string.lstrip()
'This string will be stripped\n'
Python में Regular Expressions

अभ्यास करते हैं!

Python में Regular Expressions

Preparing Video For Download...