Important Notice:

Expressions in Python

Expressions in Python

24 views 2 min read

Expressions in Python :-

Expression (एक्सप्रेशन) Python में values, variables, operators, function calls और अन्य elements का ऐसा combination है जिसे Python evaluate (मूल्यांकन) करके एक value/result (परिणाम) प्राप्त करता है।

In English:
An expression is a combination of values, variables, operators, function calls, and other elements that Python evaluates to produce a value or result.

Example:
 
10 + 20
इस Expression का result: 30

एक और उदाहरण:
a = 10
b = 20
sum=a+b
print(sum)

यहाँ a + b एक Expression है और इसका result 30 है।
 
Types of Expression with the help of Program-

# एक ही प्रोग्राम में सभी प्रकार के Expressions
a = 10
b = 3

# 1. Arithmetic Expression (गणितीय)
sum_result = a + b          # 13

# 2. Comparison Expression (तुलनात्मक)
is_greater = a > b          # True

# 3. Logical Expression (तार्किक)
logical_result = (a > 5) and (b < 5)   # True

# 4. Assignment Expression with Walrus Operator (असाइनमेंट)
if (total := a + b) > 10:
    print(f"Total is {total}, which is more than 10")

# 5. Conditional / Ternary Expression (सशर्त)
status = "Big" if a > b else "Small"

# 6. Bitwise Expression (बिटवाइज़)
bitwise_and = a & b         # 2

# 7. Membership Expression (सदस्यता)
numbers = [10, 20, 30]
check_membership = a in numbers    # True

# 8. Identity Expression (पहचान)
c = a
check_identity = a is c     # True

# सभी results को print करना
print("Sum:", sum_result)
print("Is Greater:", is_greater)
print("Logical Result:", logical_result)
print("Status:", status)
print("Bitwise AND:", bitwise_and)
print("Membership Check:", check_membership)
print("Identity Check:", check_identity)

Output-

Total is 13, which is more than 10
Sum: 13
Is Greater: True
Logical Result: True
Status: Big
Bitwise AND: 2
Membership Check: True
Identity Check: True

Related Notes