Python का पहला Program
print() Function
print() वह built-in function है जो output को screen पर लिखता है — इसे text, number या variable दीजिए, और यह नतीजा दिखाकर अगली line पर चला जाता है। सीखते समय यह देखने का सबसे तेज़ तरीका है कि आपका code असल में क्या कर रहा है।
उदाहरण: The print() Function
print("Hello, World!")
बुनियादी Strings
Python single या "double" दोनों quotes में लिखे text को एक जैसा str value मानती है, इसलिए आप वही चुन सकते हैं जिसमें escaping की झंझट न हो (जैसे, जिस string में खुद apostrophe हो उसके लिए double quotes)।
दोनों रूप कार्य में परस्पर बदले जा सकते हैं।
उदाहरण: Basic Strings
print('Hello') # single quotes work for strings
print("Hello") # double quotes work the same way
print("It's a good day") # double quotes avoid escaping the apostrophe
मानक गणनाएँ
क्योंकि print() अपना argument दिखाने से पहले उसे evaluate करता है, आप सीधे print(2 + 3) लिख सकते हैं और Python 5 निकालकर दिखा देगी, पहले अलग से गणना करने की ज़रूरत नहीं।
प्रयोग करते समय गणित की त्वरित जाँच का यह एक आसान तरीका है।
उदाहरण: Standard Calculations
print(2 + 3)
Variables का उपयोग
जैसे ही आप = से किसी variable को value देते हैं, वह बन जाता है, और उसका नाम print() को देने पर वह जो भी अभी रखे है, वह दिखता है।
क्योंकि Python dynamically typed है, वही variable बाद में बिना किसी विशेष syntax के दूसरे type की value को दोबारा दिया जा सकता है।
उदाहरण: Variables in Action
value = 10 # value starts as an integer
print(value)
value = "ten" # same variable reassigned to a string
print(value)
Program चलाना
जब आपका पहला script साफ़-साफ़ चल जाए, तो जान-बूझकर एक typo (जैसे कोई छूटा हुआ parenthesis) डालकर देखना अच्छा है कि Python का error message कैसा दिखता है — आम errors को जल्दी पहचानने से, programs बड़े होने पर debugging कहीं कम डरावनी लगती है।
उदाहरण: Running the Program
# Missing closing parenthesis -- try running this to see the error
print("Hello"
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first: