Strings

Python में डेटा टाइप्स

Jason Myers

Instructor

फ़ॉर्मेटेड strings बनाना

  • f-strings (formatted string literals) - f""
cookie_name = "Anzac"
cookie_price = "$1.99"

print(f"Each { cookie_name } cookie costs { cookie_price }.")
"Each Anzac cookie costs $1.99."
Python में डेटा टाइप्स

Strings से join करना

  • "".join() जिस string पर कॉल होता है, उसी से किसी iterable को जोड़ा जाता है
child_ages = ["3", "4", "7", "8"]

print(", ".join(child_ages))
"3, 4, 7, 8"
print(f"The children are ages {','.join(child_ages[0:3])}, and {child_ages[-1]}.")
"The children are ages 3, 4, 7, and 8."
Python में डेटा टाइप्स

String के हिस्सों का मिलान

  • .startswith() और .endswith() बताएँगे कि कोई string किसी अक्षर या दूसरी string से शुरू/समाप्त होती है या नहीं
boy_names = ["Mohamed", "Youssef", "Ahmed"]
print([name for name in boy_names if name.startswith('A')])
["Ahmed"]
  • ध्यान रखें, ये और ज़्यादातर string फंक्शन case-sensitive होते हैं.
Python में डेटा टाइप्स

Strings में चीज़ें खोजना

  • in ऑपरेटर किसी iterable जैसे string में मान को ढूँढता है.
"long" in "Life is a long lesson in humility."
True
"life" in "Life is a long lesson in humility."
False
Python में डेटा टाइप्स

Case-insensitive होने का एक तरीका

  • .lower() method लोअर-केस string लौटाता है
"life" in "Life is a long lesson in humility.".lower()
True
Python में डेटा टाइप्स

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

Python में डेटा टाइप्स

Preparing Video For Download...