Python की शुरुआत
Python क्या है?
Python एक popular, free, high-level programming language है जिसे Guido van Rossum ने बनाया (1991 में release)। इसका code लगभग English जैसा दिखता है, इसलिए CBSE Class XI और XII में यही पहली language है। YouTube, Instagram, NASA और ज़्यादातर AI tools Python use करते हैं।
C++ में same काम
#include <iostream>int main() {std::cout << "Hello";return 0; }
Python में same काम
print("Hello")- एक line – न main, न semicolons, न brackets
Python की विशेषताएँ
Python और IDLE install करना
- 1python.org/downloads खोलें और अपने computer के लिए latest Python 3 download करें।
- 2Installer चलाएँ। Windows पर "Add python.exe to PATH" tick करें, फिर Install Now दबाएँ।
- 3Start menu से IDLE (Integrated Development and Learning Environment) खोलें।
- 4आपको
>>>prompt वाला Python shell दिखेगा। Python तैयार है!
आप VS Code, Thonny, PyCharm जैसे editors या Google Colab और Jupyter Notebook जैसे online tools भी use कर सकते हैं।
Interactive mode vs script mode
Interactive mode (shell)
>>>के बाद statement type करके Enter- Result तुरंत दिखता है
- छोटी चीज़ें test करने के लिए बढ़िया
- Code save नहीं होता
Script mode (file)
- पूरा program .py extension वाली file में
- IDLE: File → New File, फिर Run → Run Module (F5)
- Program save, edit और दोबारा run हो सकता है
- सभी असली programs के लिए
>>> 5 + 3 8 >>> 'Hi' * 3 'HiHiHi' >>> 22 / 7 3.142857142857143
आपका पहला program
IDLE में File → New File चुनें, नीचे की lines type करें, hello.py नाम से save करें और F5 दबाएँ।
print('Hello, Class XI!')
print('My first Python program')
print(25 + 17)print() एक built-in function है जो screen पर output दिखाता है। Text quotes के अंदर होना चाहिए (single '…' या double "…"); numbers और calculations को quotes नहीं चाहिए।
print() के बारे में और
print() commas से अलग कई values दिखा सकता है। दो useful options: sep (values के बीच क्या आए, default space) और end (आख़िर में क्या आए, default new line)।
print('Mango', 'Apple', 'Banana') # sep is a space by default
print('Mango', 'Apple', 'Banana', sep=' | ')
print('Loading', end='...')
print('done')
print() # empty line
print('Rs.', 250 * 3)Comments
Comment इंसानों के लिए note है; Python उसे ignore करता है। Single-line comment # से शुरू होता है। लंबे notes के लिए triple quotes '''…''' वाली string use कर सकते हैं (function को describe करे तो docstring कहलाती है)।
# This program finds the area of a circle
radius = 7 # radius in cm
area = 3.14 * radius * radius
print('Area =', area, 'sq cm')ऐसे comments लिखें जो क्यों बताएँ, सिर्फ़ क्या नहीं। "# 3.14 को pi की value माना" पढ़ने वाले के लिए "# multiply" से ज़्यादा useful है।
Keywords
Keywords Python के reserved words हैं जिनका ख़ास मतलब है, जैसे if, for, while, def, True। इन्हें variable names के रूप में use नहीं कर सकते।
import keyword
print(len(keyword.kwlist), 'keywords')
print(keyword.kwlist[:10])
print(keyword.iskeyword('for'), keyword.iskeyword('marks'))| सभी 35 keywords (Python 3.7+) | ||||||
|---|---|---|---|---|---|---|
| False | None | True | and | as | assert | async |
| await | break | class | continue | def | del | elif |
| else | except | finally | for | from | global | if |
| import | in | is | lambda | nonlocal | not | or |
| pass | raise | return | try | while | with | yield |
Identifiers और naming rules
Identifier वह नाम है जो हम variable, function या class को देते हैं। Rules:
- Letters (a–z, A–Z), digits (0–9) और underscore
_हो सकते हैं। - Digit से शुरू नहीं हो सकता।
- Keyword नहीं हो सकता।
- Spaces या
@ $ % - !जैसे special symbols नहीं। - Case-sensitive:
Totalऔरtotalअलग हैं।
Valid ✔
markstotal_marks_countstudent2RollNo
Invalid ✘
2nd_name– digit से शुरूtotal marks– space हैfor– keywordprice$– special symbolmy-name– hyphen मतलब minus
2nd_name = 'Riya'
Meaningful names रखें: कोई और आपका program पढ़े तो p से percentage कहीं बेहतर है।
सारांश और practice
- Python: आसान, free, interpreted, portable, case-sensitive।
- Quick test के लिए interactive mode; programs के लिए script mode (.py file)।
sepऔरendके साथprint(); comments#से शुरू।- 35 keywords; identifier digit से शुरू या keyword नहीं हो सकता।
कौन से valid identifiers हैं? Class, class, _9marks, roll-no, none, None। फिर एक print statement लिखें जो numbers 2026 और 27 से sep use करके 2026-27 दिखाए।
Answers: valid: Class, _9marks, none; invalid: class, None (keywords), roll-no (hyphen)। print(2026, 27, sep='-')
