Python की मूल बातें

Python में वेरिएबल और डेटा टाइप

Variable किसी value को नाम देता है ताकि आप उसे बाद में इस्तेमाल कर सकें। Python type value से तय करता है, इसलिए आपको उसे अलग से declare नहीं करना पड़ता।

में वेरिएबल और डेटा टाइप क्या है?

Variable किसी value को नाम देता है ताकि आप उसे बाद में इस्तेमाल कर सकें। Python type value से तय करता है, इसलिए आपको उसे अलग से declare नहीं करना पड़ता।

Values को variables में store करें और Python के basic types: str, int, float और bool सीखें।

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

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

उदाहरण कोड

कोड चलाएँ →
main.py
# A variable is a name that refers to a value. Python works out the type for you.
name = "Ada"          # str: text
age = 36              # int: whole number
height = 1.68         # float: decimal number
is_student = False    # bool: True or False

print(name, age, height, is_student)
print(type(name), type(age), type(height), type(is_student))

# Variables can be reassigned, even to a value of another type.
age = age + 1
print("Next year:", age)

# Convert between types with int(), float(), str() and bool().
print(int("42") + 1)
print(str(3.5) + " stars")
print(float(7) / 2)

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

Ada 36 1.68 False
<class 'str'> <class 'int'> <class 'float'> <class 'bool'>
Next year: 37
43
3.5 stars
3.5

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

type() किसी value का type दिखाता है। int(), float() और str() types के बीच convert करते हैं, जो तब काम आता है जब "42" जैसा text number बनाना हो।

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

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

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

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

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

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

सभी चैलेंज