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

Operators, Input-Output और Debugging

Python में operators

Operator एक symbol है जो Python को operands नाम की values पर calculation या comparison करने को कहता है। Shops, banks और schools रोज़ इन्हें use करते हैं — GST जोड़ना, marks compare करना, eligibility जाँचना।

➕
Arithmetic+ - * / // % **
⚖️
Relational== != > < >= <=
🔗
Logicaland or not
📝
Assignment= += -= *= /=
🔍
Membershipin not in
🆔
Identityis is not
Operator families

Arithmetic operators

Python
price, gst = 1250, 18
tax = price * gst / 100
print('GST =', tax, '| Total =', price + tax)
print(29 // 4, 29 % 4, 2 ** 10, 9 / 2)
minutes = 135
print(minutes // 60, 'h', minutes % 60, 'min')
GST = 225.0 | Total = 1475.0 7 1 1024 4.5 2 h 15 min
OperatorनामExampleResult
+जोड़1250 + 2251475
-घटाव50 - 1238
*गुणा45.5 * 3136.5
/भाग9 / 24.5
//Floor division29 // 47
%Modulus (शेषफल)29 % 41
**घात2 ** 101024
Results के साथ arithmetic operators

Relational, logical और membership operators

Relational operators values compare करके True या False देते हैं। Logical operators conditions जोड़ते हैं। Membership operators जाँचते हैं कि value string, list या दूसरे collection में है या नहीं।

Python
marks, attendance = 72, 68
print(marks >= 33, attendance >= 75)
eligible = marks >= 33 and attendance >= 75
print('Eligible for exam:', eligible)
print(10 > 3 or 5 < 2, not 10 > 3)
print('IP' in 'Informatics Practices', 'ip' in 'Informatics Practices')
True False Eligible for exam: False True False False False

ध्यान दें 'IP' in 'Informatics Practices' False है — capital "IP" साथ में नहीं आते; membership case-sensitive है।

Assignment operators

Python
stock = 50
stock -= 12      # 12 sold
stock += 30      # 30 arrived
stock *= 2       # second branch has the same
print('Stock =', stock)
Stock = 136

Expressions और precedence

Expression operands और operators का मेल है जो एक value देता है। कई operators हों तो Python precedence मानता है: पहले brackets, फिर **, फिर * / // %, फिर + -, फिर comparisons, फिर not, and, or। एक ही level के operators बाएँ से दाएँ चलते हैं, सिवाय ** के जो दाएँ से बाएँ।

Python
print(5 + 3 * 2 - 8 / 4)
print((5 + 3) * 2)
print(2 ** 2 ** 3)
print(15 - 6 // 4)
9.0 16 256 14
5 + 3 * 2 - 8 / 4शुरुआत5 + 6 - 8 / 4पहले 3 * 25 + 6 - 2.0फिर 8 / 411 - 2.0बाएँ से दाएँ9.0result (/ की वजह से float)
Step-by-step evaluation

Input और output

input(prompt) user का type किया text पढ़ता है। print() values दिखाता है; spacing के लिए sep और end use करें।

Python
name = input('Customer name: ')
amount = float(input('Purchase amount: '))
if amount > 2000:
    discount = amount * 10 / 100
else:
    discount = amount * 5 / 100
print('Dear', name + ', you pay Rs.', amount - discount)
Customer name: Pooja Purchase amount: 2400 Dear Pooja, you pay Rs. 2160.0

Type conversion

Implicit conversion अपने आप होता है (int + float → float)। Explicit conversion (type casting) में int(), float(), str(), bool() use होते हैं।

Python
a = '5'
print(a * 3, int(a) * 3)                  # string repeat vs number multiply
print(int(9.99), float('12'), str(3.0), int('0012'))
print(round(1234.5678, 2), round(1234.5678, -2))
555 15 9 12.0 3.0 12 1234.57 1200.0
Python
c = float(input('Temperature in Celsius: '))
f = c * 9 / 5 + 32
print('Fahrenheit =', round(f, 2))
Temperature in Celsius: 36.6 Fahrenheit = 97.88

Errors और debugging

Runtime error – program रुक जाता है

  • Zero से भाग
  • ऐसा variable use करना जो बना ही नहीं
  • "abc" को int() से बदलना
  • Python error का नाम और line दिखाता है

Logical error – ग़लत answer

  • Program बिना message के ख़त्म
  • ग़लत formula या भूला हुआ conversion
  • Output जाँचकर ही पता चलता है
  • ढूँढना सबसे मुश्किल
दो errors जो program चलाने पर ही दिखती हैं
Python
total = 450
items = 0
print('Average price:', total / items)
ZeroDivisionError: division by zero

Classic logical error — input convert करना भूल जाना। User 3 type करता है, "total" 120 होना चाहिए, पर string "3" 40 बार दोहराई जाती है:

Python
qty = input('Quantity: ')
print('Total:', qty * 40)       # bug: qty is a string!
Quantity: 3 Total: 3333333333333333333333333333333333333333

Fix: qty = int(input('Quantity: '))। Variables और उनके types print करके debug करें: print(qty, type(qty))।

सारांश और practice

  • Arithmetic: + − * / // % **; relational True/False देते हैं; logical: and, or, not।
  • Precedence: () → ** → * / // % → + − → comparisons → not → and → or।
  • input() str देता है; int()/float() से बदलें।
  • Errors: syntax, runtime, logical।
✅ Practice

1) 20 - 3 ** 2 // 4 * 2 evaluate करें। 2) Cost price और selling price input करके profit या loss की रकम और percentage print करने वाला program लिखें। 3) Seconds को hours, minutes और seconds में बदलने वाला program लिखें।

Answer 1: 3 ** 2 = 9 → 9 // 4 = 2 → 2 * 2 = 4 → 20 − 4 = 16।

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

// operator क्या करता है?
Floor division: भाग देकर quotient को नीचे की ओर पूर्ण संख्या में देता है। 29 // 4 = 7।
Input को int() या float() से बदलना क्यों ज़रूरी है?
input() text देता है। बिना conversion के "3" * 40 गुणा करने की जगह text को 40 बार दोहराता है, और "25" + "5" से "255" मिलता है।
Errors के तीन प्रकार कौन से हैं?
Syntax errors (code Python के rules तोड़ता है), runtime errors (चलते समय program crash, जैसे zero से भाग) और logical errors (program चलता है पर result ग़लत)।
← Class 11 Informatics Practices
🔗

Share this topic with a friend

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

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

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

अगला topicFunctions और if-elif-else आपकी प्रगति: 5 / 20 (25%) · Lesson 6 / 20 आगे बढ़ें →

यह lesson कैसा लगा?

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

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

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

▶ CodingEasily on YouTube

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

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

▶ Channel subscribe करें