Python की मूल बातें

Python में स्ट्रिंग

String characters की एक sequence होती है। आप position से single characters पढ़ सकते हैं, slices ले सकते हैं, और methods call कर सकते हैं जो बदली हुई copies लौटाते हैं।

में स्ट्रिंग क्या है?

String characters की एक sequence होती है। आप position से single characters पढ़ सकते हैं, slices ले सकते हैं, और methods call कर सकते हैं जो बदली हुई copies लौटाते हैं।

Python में text के साथ काम करें: length, indexing, slicing और string methods।

इसका उपयोग कब करें?

  • चलने योग्य code से Python syntax सीखें।
  • बड़ी programming समस्याओं से पहले मजबूत आधार बनाएँ।
  • स्थानीय setup के बिना किसी विचार को तुरंत जाँचें।

उदाहरण कोड

कोड चलाएँ →
main.py
text = "Python is fun"

print(len(text))          # number of characters
print(text[0], text[-1])  # first and last character
print(text[0:6])          # slicing: characters 0 to 5
print(text.upper())
print(text.lower())
print(text.replace("fun", "powerful"))
print(text.split())       # split on spaces into a list
print("is" in text)       # check for a substring

# Strings are immutable: methods return a new string.
name = "  ada lovelace  "
clean = name.strip().title()
print(clean)

# Join a list of strings with a separator.
print("-".join(["2026", "11", "01"]))

अपेक्षित आउटपुट

13
P n
Python
PYTHON IS FUN
python is fun
Python is powerful
['Python', 'is', 'fun']
True
Ada Lovelace
2026-11-01

यह कैसे काम करता है

Indexes 0 से शुरू होते हैं और negative indexes end से गिनते हैं। text[0:6] जैसे slices end index से पहले रुकते हैं, और strip(), title() और replace() जैसे methods new strings लौटाते हैं क्योंकि strings in place नहीं बदलतीं।

मान बदलें और Python इंस्टॉल किए बिना CodeUtility ऑनलाइन Python कंपाइलर में प्रोग्राम चलाएँ।

अभ्यास के कार्य

बड़े dataset पर जाने से पहले input बदलें और edge cases की जाँच करें।

  1. Code चलाने से पहले output का अनुमान लगाएँ।
  2. खाली और गलत input संभालें।
  3. Logic को function में रखें और tests जोड़ें।
Python IDE में चलाएँ →

चैलेंज से अभ्यास करें

इस पाठ में सीखी बात से एक असली समस्या हल करें। हर चैलेंज ब्राउज़र में चलता है, तुरंत टेस्ट और AI रिव्यू के साथ।

सभी चैलेंज