← Back to Python Course | Chapter 1: Basics | Lesson 4 of 14

Python का पहला Program

आपका पहला प्रोग्राम एक तोते को उसका पहला शब्द सिखाने जैसा है। आप कंप्यूटर को स्क्रीन पर एक संदेश दिखाने के लिए कहते हैं, और वह ठीक वैसा ही करता है।

print() Function

print() वह built-in function है जो output को screen पर लिखता है — इसे text, number या variable दीजिए, और यह नतीजा दिखाकर अगली line पर चला जाता है। सीखते समय यह देखने का सबसे तेज़ तरीका है कि आपका code असल में क्या कर रहा है।

उदाहरण: The print() Function

python
print("Hello, World!")

बुनियादी Strings

Python single या "double" दोनों quotes में लिखे text को एक जैसा str value मानती है, इसलिए आप वही चुन सकते हैं जिसमें escaping की झंझट न हो (जैसे, जिस string में खुद apostrophe हो उसके लिए double quotes)।

दोनों रूप कार्य में परस्पर बदले जा सकते हैं।

उदाहरण: Basic Strings

python
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

python
print(2 + 3)

Variables का उपयोग

जैसे ही आप = से किसी variable को value देते हैं, वह बन जाता है, और उसका नाम print() को देने पर वह जो भी अभी रखे है, वह दिखता है।

क्योंकि Python dynamically typed है, वही variable बाद में बिना किसी विशेष syntax के दूसरे type की value को दोबारा दिया जा सकता है।

उदाहरण: Variables in Action

python
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

python
# Missing closing parenthesis -- try running this to see the error
print("Hello"
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.