Operators and Expression in Python

Operators and Expression in Python

Introduction परिचय

The python operators, expressions and statements are the key part of this programming language. In this, the python symbol which is the responsible to perform certain activity, that symbol is by default considered as python Operator (like addition, multiplication, subtraction etc.). The values on which the operator acts are called operands.

पाइथन आपरेटर, एक्सप्रेशन, और एस्टेटमेंट इस प्रोग्रामिंग लैंगवेज के एक महत्वपूर्ण पार्ट है। इसमें पाइथन सिम्बल जो कुछ एक्टिविटी को करने के लिए रिस्पॉन्सबिल हैं, वह सिम्बल डिफॉल्ट रूप से पायथन ऑपरेटर (जैसे जोड़, गुणा आदि) के रूप में माना जाता है। वे वैल्यू जो उस ऑपरेटर पर कार्य करते हैं उन्हें ऑपरेंड कहा जाता है।

For example:

>>> a = 10 
>>> b = 20 
>>> a + b 
30

In the above example, the ‘+’ operator adds the operands ‘a’ and ‘b’ together. An operand can be either a literal value or a variable that references an object.

उपरोक्त उदाहरण में, ‘+’ ऑपरेटर ऑपरेंड ‘a’ और ‘b’ को आपस में जोड़ता है। एक ऑपरेंड या तो एक लिटरल या एक वैरिएबल हो सकता है जो किसी ऑब्जेक्ट को संदर्भित करता है।

For example:

>>>  a = 10 
>>>  a  +  (a - 10) * 5
10

A sequence of operands and operators, like ‘a + (a – 10) * 5’, is called an expression. Python supports many operators for combining data objects into expressions.

ऑपरेंड्स और ऑपरेटर्स का एक सिक्वेंस, जैसे ‘a + (a – 10) *. 5’ को एक एक्सप्रेशन कहा जाता है। पाइथन डेटा ऑब्जेक्ट्स को एक्सप्रेशन में संयोजित करने के लिए कई ऑपरेटरों का समर्थन करता है।

Assignment statement
असाइनमेंट स्टेटमेंट

Assignment operator or the equal sign (=) is used to assign values to variables. The operand to the left of the ‘=’ operator is the name of the variable and the operand to the right of the ‘=’ operator is the value stored in the variable.

असाइनमेंट ऑपरेटर या बराबर चिह्न (=) का उपयोग वैरिएबल को वैल्यू असाइन करने के लिए किया जाता है। ‘=’ ऑपरेटर के बाईं ओर वाला ऑपरेंड वैरिएबल का नाम है और ऑपरेटर के दाईं ओर वाला ऑपरेंड वैरिएबल में स्टोर किया गया वैल्यू है।

For example:
val = 100

Here, val = 100, that assigns the value ‘100’ on the right to the variable ‘val’ on the left. यहां, val = 100, जो वैल्यू 100 एसाइन करता है जो वैरिएबल के दाईं ओर ‘val’ बाईं तरफ है।

In Python, you can assign a single value to multiple variables simultaneously. पाइथन में, आप एक साथ कई वैरिएबल के लिए एक ही वैल्यू एसाइन कर सकते है।

For example:
x = y = z = 101

Here, an integer object is created with the value ‘101’, and all three variables are assigned to the same memory location.

यहाँ, 101 वैल्यू के साथ एक इंटीजर ऑब्जेक्ट बनाया गया है, और सभी तीन वैरियेबल एक ही मेमोरी स्थान पर असाइन किए गए हैं।

In Python, you can also assign multiple objects to multiple variables.

पाइथन में, आप कई ऑब्जेक्ट्स को कई वेरिएबल्स में भी असाइन कर सकते हैं।

For example:
rollNo,  SName,  sDivision = 101,  “Gyancs “,  89.5

Here you will see…

One integer object with value ‘101’ is assigned to variable ‘rollNo’.

वैल्यू ‘101’ के साथ एक इंटीजर ऑब्जेक्ट को ‘रोल नं0’ के लिए एसाइन किया गया है।

One string objects with value ‘gyancs’ is assigned to variable ‘sName’.

वैल्यू ‘gyancs’ के साथ एक स्टिंग ऑब्जेक्ट को वैरिएबल ‘sName’ से असाइन किया गया है।

And one float object with the value ‘89.5’ is assigned to the variable ‘sDivision’.

और एक फ्लोट ऑब्जेक्ट वैल्यू ‘89.5’ के साथ एक वैरिएबल ‘sDivision’ से असाइन किया गया है।

There are various compound operators in Python like ‘val += 5’ that adds to the variable and later assigns the same. It is equivalent to ‘val = val + 5’.

पायथन में विभिन्न कंपाउंड ऑपरेटर हैं जैसे ‘val += 5’ जो वैरिएबल में जुड़ते हैं और बाद में उसी को असाइन करते हैं। यह ‘val = val + 5’ के बराबर हैं।

Example:

val = 50 
print('val = ', val) 
print('val + 5 = ', val + 5) 
print('val - 5 = ', val - 5) 
print('val * 5 = ', val * 5) 
print('val / 5 = ', val /.5) 
print('val % 5 = ', val % 5) 
print('val // 5 = ', val // 5) 
print('val ** 5 = ', val ** 5) 
print('val & 5 = ', val & 5)
print('val | 5 = ', val | 5) 
print('val ^5 = ', val ^ 5) 
print('val >> 5 = ', val >> 5) 
print('val < 5 = ', val < 5)

Output:
val =  50
val + 5 =  55
val – 5 =  45
val * 5 =  250
val / 5 =  100.0
val % 5 =  0
val // 5 =  10
val ** 5 =  312500000
val & 5 =  0
val | 5 =  55
val ^5 =  55
val >> 5 =  1
val < 5 =  False

Expressions एक्सप्रेशन

An expression is an instruction that combines values and operators and always evaluates down to a single value. Python expressions only contain identifiers, literals, and operators.

एक एक्सप्रेशन एक निर्देश है जो वैल्यू और ऑपरेटरों को जोड़ता है और हमेशा एक वैल्यू पर नीचे की ओर मूल्यांकन करता है। पाइथन के एक्सप्रेशन में केवल आइडेंटिफायर, लिटरल, और ऑपरेटर्स होते हैं।

  • Identifiers: Any name that is used to define a class, function, variable module, or object is an identifier. आइडेंटिफायर: कोई भी नाम जिसका उपयोग किसी क्लॉस, फंक्शन, वेरिएबल मॉड्यूल या ऑब्जेक्ट को परिभाषित करने के लिए किया जाता है।

  • Literals: These are language-independent terms in Python and should exist independently in any programming language. In Python, there are the string literals, byte literals, integer literals, floating point literals, and imaginary literals.

लिटरलः ये पाइथन में लैग्वेज इंडिपेंडेंट टर्म हैं और किसी भी प्रोग्रामिंग भाषा में स्वतंत्र रूप से मौजूद होने चाहिए। पॉयथन में, स्ट्रिंग लिटरल, बाइट लिटरल, इंटीजर लिटरल, फ्लोटिंग प्वाइंट लिटरल और इमेजनरी (काल्पनिक) लिटरल हैं।

  • Operators: In Python you can implement the following operations using the corresponding tokens.

पॉयथन में आप इसी टोकन का उपयोग करके निम्नलिखित कार्यों को कार्यान्वित कर सकते हैं।

Arithmetic – अंकगणित

The various arithmetic calculations as addition, subtraction, multiplication, division, modulus, exponent, etc can be perform in Python, you can use the eval function, declare variable & calculate.

पॉयथन में जोड़, घटाना, गुणा, भाग, मॉड्यूल्स, एक्सपोनेन्ट आदि विभिन्न अंकगणितीय गणनाएं की जा सकती हैं, आप eval फंक्शन का उपयोग कर सकते हैं, वैरियेबल डिक्लेयर कर सकते हैं

For this Python Arithmetic operator’s example, we are using two variables ‘a’ and ‘b’ and their values are 23 and 7. We are going to use these two variables to perform various arithmetic operations in Python programming.

इस पॉयथन अरिथमेटिक ऑपरेटर के उदाहरण के लिए, हम दो वैरियेबल ‘a’ और ‘b’ का उपयोग कर रहे हैं और उनके वैल्यू 23 और 7 हैं। हम पॉयथन प्रोग्रामिंग में विभिन्न अरिथमेटिक ऑपरेशन करने के लिए इन दो वैरिऐबल का उपयोग करने जा रहे हैं।

a = int(input ("Enter a number: ")) 
b = int(input ("Enter b number : "))
print ("Addition of two numbers 23 and 7 is : ", a + b)
print("Subtracting Number 7 from 23 is : ", a - b) 
print ("Multiplication of two numbers 23 and 7 is : ", a * b) 
print("Division of two numbers 23 and 7 is : ", a / b) 
print ("Modulus of two numbers 23 and 7 is : ", a % b) 
print ("Exponent of two numbers 23 and 7 is : ", a ** b)
print("Floor Division of two numbers 23 and 7 is : ", a // b)

Output:
Enter a number :9
Enter b number : 5
Addition of two numbers 23 and 7 is: 14
Subtracting Number 7. from 23 is : 4
Multiplication of two numbers 23 and 7 is : 45
Division of two numbers 23 and 7 is : 1.8
Modulus of two numbers 23 and 7 is : 4
Exponent of two numbers 23 and 7 is : 59049
Floor Division of two numbers 23 and 7 is : 1

Chapter wise Model Paper Link

About Me