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

Python Basics: Tokens, Variables, Types

Informatics Practices के लिए Python क्यों?

Informatics Practices पूरी तरह data के साथ काम करने के बारे में है — उसे इकट्ठा करना, store करना, analyse करना और दिखाना। Data के काम के लिए Python सबसे popular language है क्योंकि यह पढ़ने में आसान, free है, और इसकी NumPy (numbers), Pandas (tables) और Matplotlib (charts) जैसी powerful libraries हैं, जो आप Class XI और XII में use करेंगे।

Python basicsClass XILists, dictionariesClass XINumPyClass XIPandas + MatplotlibClass XII
IP में आपकी Python यात्रा

Execution modes

Interactive mode

  • >>> prompt वाला Python shell
  • एक statement type करें, result तुरंत
  • Calculator जैसा; कुछ save नहीं होता

Script mode

  • Program .py file में लिखें
  • Save करके run करें (IDLE में F5)
  • पूरे programs के लिए
Python चलाने के दो तरीके
Python shell
>>> 45.5 * 3
136.5
>>> 'IP' * 4
'IPIPIPIP'
>>> 100 / 8
12.5

पहला program

Python
# Shop bill – our first IP program
item = 'Notebook'
price = 45.5
qty = 3
bill = price * qty
print('Item:', item)
print('Bill: Rs.', bill)
Item: Notebook Bill: Rs. 136.5

Tokens: सबसे छोटी units

जैसे वाक्य शब्दों और विराम चिह्नों से बनता है, वैसे ही Python statement tokens से बनता है।

tokens →bill=price*qty+20
bill = price * qty + 20 → 7 tokens
Token typeमतलबExamples
Keywordतय मतलब वाला reserved wordif, else, for, while, True, None
IdentifierProgrammer का दिया नामbill, price, total_marks
LiteralFixed value20, 45.5, 'Pen', True
OperatorOperation करने वाला symbol+ - * / == and
PunctuatorCode को ढाँचा देने वाले symbols( ) [ ] { } , : . ' #
Tokens के पाँच प्रकार

Keywords और identifiers

Keywords reserved words हैं (नए Python में 35) — इन्हें नाम के रूप में use नहीं कर सकते। Identifiers variables, functions वगैरह के नाम हैं। Identifier के rules: सिर्फ़ letters, digits और underscore; digit से शुरू नहीं; keyword नहीं; case-sensitive।

Valid identifiers

  • price
  • total_bill
  • _tax
  • item2
  • Qty (qty से अलग)

Invalid identifiers

  • 1item – digit से शुरू
  • total bill – space
  • while – keyword
  • rate% – symbol
  • gst-rate – hyphen
नाम की जाँच

Literals

Literal program में सीधे लिखी गई raw value है।

LiteralExamples
Numeric – integer25, -7, 0o17 (octal), 0x1F (hex), 0b101 (binary)
Numeric – float3.14, -0.5, 2.5e3
Numeric – complex3+2j
String'Pen', "Delhi", '''multi-line'''
BooleanTrue, False
SpecialNone
Python
print(0o17, 0x1F, 0b101)          # octal, hex, binary integer literals
print(2.5e3, 3 + 2j)              # float in exponent form, complex
print('It\'s', "say \"hi\"")       # escape quotes with backslash
print('Line1\nLine2\tTabbed')      # \n new line, \t tab
print(True, False, None)          # boolean and special literals
15 31 5 2500.0 (3+2j) It's say "hi" Line1 Line2 Tabbed True False None

Escape sequences backslash से शुरू होते हैं: \n नई line, \t tab, \\ backslash, \' और \" quotes।

Variables और assignment

Variable memory में रखी value को refer करने वाला नाम है। पहली बार assign करने पर बनता है। Python dynamically typed है:

Python
score = 50
print(score, type(score))
score = 'fifty'          # same name, now a string (dynamic typing)
print(score, type(score))
50 <class 'int'> fifty <class 'str'>
Python
a = b = c = 100          # same value to many variables
x, y, z = 'Red', 'Green', 'Blue'
print(a, b, c)
print(x, y, z)
print(id(a) == id(b))    # both names refer to one object
100 100 100 Red Green Blue True
a, b, cतीन नामrefer to100एक int object
a = b = c = 100 – सभी नाम एक ही object को refer करते हैं

Comments

Comments इंसानों को code समझाते हैं और Python उन्हें ignore करता है। Comment # से शुरू करें। Formulas और ज़रूरी steps के लिए comments लिखें, जैसे # GST at 18% is added to the price।

Data types

🔢
Numberint (25), float (45.5), complex (3+2j)
✅
BooleanTrue / False – conditions का result
🔤
String (str)Quotes में text: 'Notebook'
📋
ListOrdered, बदलने वाली: [45, 102, 8]
📍
TupleOrdered, fixed: (28.61, 77.21)
📒
DictionaryKey: value pairs: {'runs': 102}
🔘
SetUnique items: {1, 2, 3}
∅
Noneकोई value नहीं
Python data types
Python
item, price, qty, in_stock = 'Notebook', 45.5, 3, True
print(type(item), type(price), type(qty), type(in_stock))
runs = [45, 102, 8]                  # list
player = {'name': 'Virat', 'runs': 102}   # dictionary
location = (28.61, 77.21)            # tuple
print(runs, player['runs'], location[0])
print(type(runs), type(player), type(location))
<class 'str'> <class 'float'> <class 'int'> <class 'bool'> [45, 102, 8] 102 28.61 <class 'list'> <class 'dict'> <class 'tuple'>

Mutable types बनने के बाद बदल सकते हैं (list, dictionary, set); immutable नहीं (int, float, bool, str, tuple)।

सारांश और practice

  • Data के काम के लिए Python मुख्य language है (NumPy, Pandas, Matplotlib)।
  • Tokens: keywords, identifiers, literals, operators, punctuators।
  • Variables assignment से बनते हैं; Python dynamically typed है।
  • Types: int, float, complex, bool, str, list, tuple, dict, set, None।
✅ Practice

1) avg = (a + b) / 2 में tokens गिनें। 2) हर literal का type बताइए: '2026', 2026, 20.26, False। 3) दो items का नाम, price और quantity store करके total bill print करने वाला program लिखें।

Answers: 1) 9 tokens: avg = ( a + b ) / 2। 2) str, int, float, bool।

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

Python में tokens क्या हैं?
Tokens program की सबसे छोटी अर्थपूर्ण units हैं: keywords, identifiers, literals, operators और punctuators (brackets, commas, colons जैसे delimiters)।
Literal क्या है?
Code में सीधे लिखी fixed value, जैसे 25, 3.14, "Hello", True या None।
Dynamic typing क्या है?
Python में variable का type run time पर assign की गई value से तय होता है, और वही variable बाद में दूसरे type की value रख सकता है।
← Class 11 Informatics Practices
🔗

Share this topic with a friend

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

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

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

अगला topicOperators, Input-Output और Debugging आपकी प्रगति: 4 / 20 (20%) · Lesson 5 / 20 आगे बढ़ें →

यह lesson कैसा लगा?

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

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

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

▶ CodingEasily on YouTube

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

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

▶ Channel subscribe करें