Free tutorials & notes in Hindi & English · Clean code examples 🧰 मुफ़्त PDF और फ़ोटो टूल्स →
🐍 Unit 2 – Python Basics  ·  Lesson 11

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 की विशेषताएँ

📖
पढ़ने में आसानSimple English जैसा syntax; { } की जगह indentation।
🆓
Free और open sourcepython.org से free download; कोई भी सुधार कर सकता है।
🧑‍💻
InterpretedLine by line चलती है, इसलिए errors ढूँढना आसान।
💻
PortableSame program Windows, Linux, macOS पर चलता है।
📚
बड़ी libraryMaths, data, web, games, AI के ready modules।
🔤
Case-sensitiveMarks, marks और MARKS तीन अलग नाम हैं।
Python क्यों?

Python और IDLE install करना

  1. 1python.org/downloads खोलें और अपने computer के लिए latest Python 3 download करें।
  2. 2Installer चलाएँ। Windows पर "Add python.exe to PATH" tick करें, फिर Install Now दबाएँ।
  3. 3Start menu से IDLE (Integrated Development and Learning Environment) खोलें।
  4. 4आपको >>> prompt वाला Python shell दिखेगा। Python तैयार है!
चार steps में Python install

आप 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 के लिए
Python चलाने के दो तरीके
Python shell
>>> 5 + 3
8
>>> 'Hi' * 3
'HiHiHi'
>>> 22 / 7
3.142857142857143

आपका पहला program

IDLE में File → New File चुनें, नीचे की lines type करें, hello.py नाम से save करें और F5 दबाएँ।

Python
print('Hello, Class XI!')
print('My first Python program')
print(25 + 17)
Hello, Class XI! My first Python program 42

print() एक built-in function है जो screen पर output दिखाता है। Text quotes के अंदर होना चाहिए (single '…' या double "…"); numbers और calculations को quotes नहीं चाहिए।

print() commas से अलग कई values दिखा सकता है। दो useful options: sep (values के बीच क्या आए, default space) और end (आख़िर में क्या आए, default new line)।

Python
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)
Mango Apple Banana Mango | Apple | Banana Loading...done Rs. 750

Comments

Comment इंसानों के लिए note है; Python उसे ignore करता है। Single-line comment # से शुरू होता है। लंबे notes के लिए triple quotes '''…''' वाली string use कर सकते हैं (function को describe करे तो docstring कहलाती है)।

Python
# This program finds the area of a circle
radius = 7          # radius in cm
area = 3.14 * radius * radius
print('Area =', area, 'sq cm')
Area = 153.86 sq cm
💡 अच्छी आदत

ऐसे comments लिखें जो क्यों बताएँ, सिर्फ़ क्या नहीं। "# 3.14 को pi की value माना" पढ़ने वाले के लिए "# multiply" से ज़्यादा useful है।

Keywords

Keywords Python के reserved words हैं जिनका ख़ास मतलब है, जैसे if, for, while, def, True। इन्हें variable names के रूप में use नहीं कर सकते।

Python
import keyword
print(len(keyword.kwlist), 'keywords')
print(keyword.kwlist[:10])
print(keyword.iskeyword('for'), keyword.iskeyword('marks'))
35 keywords ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class'] True False
सभी 35 keywords (Python 3.7+)
FalseNoneTrueandasassertasync
awaitbreakclasscontinuedefdelelif
elseexceptfinallyforfromglobalif
importinislambdanonlocalnotor
passraisereturntrywhilewithyield

Identifiers और naming rules

Identifier वह नाम है जो हम variable, function या class को देते हैं। Rules:

  1. Letters (a–z, A–Z), digits (0–9) और underscore _ हो सकते हैं।
  2. Digit से शुरू नहीं हो सकता।
  3. Keyword नहीं हो सकता।
  4. Spaces या @ $ % - ! जैसे special symbols नहीं।
  5. Case-sensitive: Total और total अलग हैं।

Valid ✔

  • marks
  • total_marks
  • _count
  • student2
  • RollNo

Invalid ✘

  • 2nd_name – digit से शुरू
  • total marks – space है
  • for – keyword
  • price$ – special symbol
  • my-name – hyphen मतलब minus
नाम रखने से पहले check करें
Python
2nd_name = 'Riya'
SyntaxError: invalid decimal literal

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 नहीं हो सकता।
✅ Practice

कौन से 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='-')

अक्सर पूछे जाने वाले प्रश्न (FAQ)

Python किसने बनाई?
Guido van Rossum ने Python बनाई और 1991 में release की। इसका नाम comedy show "Monty Python’s Flying Circus" पर है, साँप पर नहीं।
Python में कितने keywords हैं?
Python 3.7 और नए versions में 35 keywords हैं। import keyword; print(keyword.kwlist) से देख सकते हैं। True, False और None capital letter से शुरू होते हैं।
क्या identifier digit से शुरू हो सकता है?
नहीं। Identifier letter या underscore से शुरू होना चाहिए। पहले character के बाद digits आ सकते हैं, जैसे marks2 या _total।
← Class 11 Computer Science
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

अगला topicVariables, Data Types और Mutability आपकी प्रगति: 11 / 29 (38%) · Lesson 12 / 29 आगे बढ़ें →

यह lesson कैसा लगा?

आपकी राय से हम content और बेहतर बनाते हैं।

अपना review और सुझाव लिखें (वैकल्पिक)

Review approve होने के बाद आपका नाम और शहर इसके साथ public दिख सकते हैं। Email या phone न लिखें।

▶ CodingEasily on YouTube

Video से सीखें – आसान Hindi में

चुनी हुई video: RDBMS भाग 3 – Class XI Commerce IT

▶ Channel subscribe करें