Expressions in Python in Hindi – Expression Kya Hai?
Table of Contents
1. Introduction to Expressions in Hindi – Expression Kya Hai?
3. Evaluation of Expressions in Hindi – Expression कैसे Evaluate होती है?
4. Expression Examples in Python in Hindi – Expressions के उदाहरण
Introduction to Expressions in Hindi – Expression Kya Hai?
Python में program लिखते वक्त हम अक्सर values के साथ calculations करते हैं, comparisons करते हैं, या फिर conditions check करते हैं, यह सारा काम जिसकी मदद से होता है उसे Expression कहा जाता है।
Simple भाषा में कहें तो Expression एक ऐसा combination होता है जो variables, values (constants) और operators को मिलाकर बनाया जाता है, और जिसे evaluate करने पर हमेशा एक single value मिलती है।
जैसे स्कूल में हम maths में
5 + 3जैसा एक arithmetic expression लिखते थे जिसका result 8 आता है, ठीक उसी तरह Python में भी expressions को evaluate करने पर एक निश्चित result निकलता है।हर expression में कम से कम एक operand (value या variable) और आमतौर पर एक operator (जैसे +, -, ==) होता है, हालांकि सिर्फ एक अकेली value (जैसे सिर्फ
10) भी एक valid expression मानी जाती है।Python interpreter जब भी किसी expression को देखता है, तो वह उसे तुरंत evaluate (हल) करके एक value में बदल देता है, यही process Expression Evaluation कहलाता है।
Expressions और Statements में एक बुनियादी फर्क होता है – Expression हमेशा कोई value return करती है (जैसे
a + b), जबकि Statement सिर्फ कोई action perform करता है (जैसेprint(a)याifblock)।Exam की नज़र से देखा जाए तो Expression का मतलब है – "variables, values aur operators ka wo combination jise evaluate karne par ek single value milti hai."
Types of Expressions in Hindi – Expression के प्रकार
-
1. Arithmetic Expression:
इस type के expression में numbers के साथ mathematical operators (जैसे +, -, *, /, %, **) इस्तेमाल किए जाते हैं, और result भी हमेशा एक number ही होता है।a = 10 b = 3 result = a + b * 2 print(result) # Output: 16 -
2. Relational (Comparison) Expression:
इस type के expression में दो values को compare किया जाता है (जैसे ==, !=, >, <, >=, <=), और इसका result हमेशा Boolean value (True या False) में आता है।x = 15 y = 20 print(x > y) # Output: False print(x != y) # Output: True -
3. Logical Expression:
इसमें एक से ज्यादा conditions को logical operators (and, or, not) की मदद से जोड़ा जाता है, इसका result भी हमेशा True या False ही होता है।age = 25 has_id = True print(age >= 18 and has_id) # Output: True -
4. String Expression:
इसमें strings के साथ operators इस्तेमाल किए जाते हैं, जैसे+operator से दो strings को जोड़ना (concatenation) या*operator से किसी string को कई बार repeat करना।first = "Hello" second = "Python" print(first + " " + second) # Output: Hello Python print("Hi! " * 3) # Output: Hi! Hi! Hi! -
5. Assignment Expression:
इसमें किसी variable को कोई value assign की जाती है, इसमें simple=के अलावा shorthand operators (जैसे +=, -=, *=) भी इस्तेमाल किए जाते हैं।total = 50 total += 10 # total = total + 10 print(total) # Output: 60
Evaluation of Expressions in Hindi – Expression कैसे Evaluate होती है?
जब किसी expression में एक से ज्यादा operators इस्तेमाल किए जाते हैं, तो Python उन्हें random order में नहीं, बल्कि एक fixed Operator Precedence (प्राथमिकता) के हिसाब से evaluate करता है।
Operator Precedence का मतलब है कि किस operator को पहले और किसको बाद में calculate किया जाएगा, जैसे multiplication और division हमेशा addition और subtraction से पहले evaluate होते हैं।
Python में Operators की precedence (ऊपर से नीचे, ज्यादा से कम priority) कुछ इस तरह होती है:
| Priority | Operators | Example |
|---|---|---|
| 1 (Highest) | ** (Exponent) | 2 ** 3 = 8 |
| 2 | *, /, //, % (Multiplication/Division) | 10 / 2 = 5.0 |
| 3 | +, - (Addition/Subtraction) | 10 + 2 = 12 |
| 4 | <, <=, >, >=, ==, != (Relational) | 10 > 2 = True |
| 5 | not | not True = False |
| 6 | and | True and False = False |
| 7 (Lowest) | or | True or False = True |
अगर एक ही priority वाले कई operators एक साथ इस्तेमाल हों (जैसे
10 - 3 + 2), तो उन्हें आमतौर पर left से right की तरफ evaluate किया जाता है, इसे Associativity कहा जाता है।अगर किसी expression को default precedence से हटकर, किसी अलग order में evaluate करवाना हो, तो parentheses
( )का इस्तेमाल किया जाता है, क्योंकि parentheses की priority सबसे ज्यादा होती है।
result1 = 10 + 2 * 3 # Pehle multiplication: 2*3=6, phir 10+6=16
print(result1) # Output: 16
result2 = (10 + 2) * 3 # Pehle bracket: 10+2=12, phir 12*3=36
print(result2) # Output: 36
ऊपर के दोनों examples में ध्यान दीजिए कि numbers same हैं (10, 2, 3), लेकिन सिर्फ parentheses लगाने की वजह से evaluation order बदल गया, और result भी बिल्कुल अलग आया, यही Operator Precedence की importance को दिखाता है।
Expression Examples in Python in Hindi – Expressions के उदाहरण
Example 1: Mixed Arithmetic Expression
a = 5
b = 10
c = 2
result = a + b / c - 1
print(result) # Output: 9.0
यहां पहले b / c (10 / 2 = 5.0) evaluate होगा, फिर a + 5.0 (5 + 5.0 = 10.0), और आखिर में 10.0 - 1 यानी final result 9.0 आएगा।
Example 2: Relational aur Logical Expression Ek Saath
marks = 78
attendance = 85
is_eligible = marks >= 40 and attendance >= 75
print(is_eligible) # Output: True
यहां पहले दोनों relational expressions (marks >= 40 और attendance >= 75) अलग-अलग evaluate होंगी, और फिर उनके result को and operator से जोड़ा जाएगा।
Example 3: String Expression
first_name = "Aman"
last_name = "Sharma"
full_name = first_name + " " + last_name
print(full_name) # Output: Aman Sharma
Example 4: Assignment Expression with Shorthand Operators
score = 100
score -= 20 # score = score - 20
score *= 2 # score = score * 2
print(score) # Output: 160
Example 5: Expression with Parentheses (Real-World Style)
principal = 1000
rate = 5
time = 2
simple_interest = (principal * rate * time) / 100
print("Simple Interest hai:", simple_interest) # Output: 100.0
इस last example में parentheses का इस्तेमाल इसलिए किया गया है ताकि पहले principal * rate * time पूरा multiply हो जाए, और उसके बाद ही उसे 100 से divide किया जाए, यह एक बहुत ही common real-world formula (Simple Interest) का उदाहरण है जो सीधे तौर पर Expression Evaluation के concept को इस्तेमाल करता है।
Frequently Asked Questions (FAQ) – Expressions in Python in Hindi
Variables, values aur operators का वह combination जिसे evaluate करने पर एक single value मिलती है, उसे Expression कहते हैं।
Expression हमेशा evaluate होकर कोई value return करती है (जैसे a + b), जबकि Statement सिर्फ कोई action perform करता है (जैसे print() या if block), जरूरी नहीं कि वह कोई value return करे।
मुख्य रूप से Python में Arithmetic, Relational, Logical, String और Assignment Expressions जैसे types होते हैं।
Operator Precedence यह decide करती है कि किसी expression में कौन सा operator पहले evaluate होगा, जैसे multiplication और division हमेशा addition और subtraction से पहले evaluate होते हैं।
Default operator precedence को override करके, किसी particular हिस्से को पहले evaluate करवाने के लिए parentheses ( ) का इस्तेमाल किया जाता है, क्योंकि parentheses की priority सबसे ज्यादा होती है।