खोज और बदलना

Python में Regular Expressions

Maria Eugenia Inzaugarat

Data scientist

Substrings खोजना

  • टार्गेट स्ट्रिंग में दिए गए सबस्ट्रिंग को खोजें.

my_string = "Where's Waldo?"
my_string.find("Waldo")
8
my_string.find("Wenda")
-1
Python में Regular Expressions

Substrings खोजना

  • टार्गेट स्ट्रिंग में दिए गए सबस्ट्रिंग को खोजें.

my_string = "Where's Waldo?"
my_string.find("Waldo", 0, 6)
-1
Python में Regular Expressions

Index फंक्शन

  • .find() जैसा, टार्गेट स्ट्रिंग में दिए गए सबस्ट्रिंग को खोजें.

my_string = "Where's Waldo?"
my_string.index("Waldo")
8
my_string.index("Wenda")
File "<stdin>", line 1, in <module> 
ValueError: substring not found
Python में Regular Expressions

Index फंक्शन

  • .find() जैसा, टार्गेट स्ट्रिंग में दिए गए सबस्ट्रिंग को खोजें.

my_string = "Where's Waldo?"
try:
    my_string.index("Wenda")
except ValueError:
      print("Not found")
"Not found"
Python में Regular Expressions

Occurrences गिनना

  • दिए गए सबस्ट्रिंग की आवृत्तियों की संख्या लौटाएँ.

my_string = "How many fruits do you have in your fruit basket?"
my_string.count("fruit")
2
my_string.count("fruit", 0, 16)
1
Python में Regular Expressions

Substrings बदलना

  • सबस्ट्रिंग की आवृत्तियों को नए सबस्ट्रिंग से बदलें.

my_string = "The red house is between the blue house and the old house"
print(my_string.replace("house", "car"))
The red car is between the blue car and the old car
print(my_string.replace("house", "car", 2))
The red car is between the blue car and the old house
Python में Regular Expressions

समापन

  • String manipulation:

    • Slice और concatenate
    • केस समायोजित करें
    • Split और join
    • शुरुआत और अंत से कैरेक्टर हटाएँ
    • Substrings खोजना
    • Occurrences गिनना
    • Substrings बदलना
Python में Regular Expressions

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

Python में Regular Expressions

Preparing Video For Download...