Python Operators In Hindi

📔 : Python 🔗

Operator एक symbol होते हैं , जो process / operation represent करते हैं करते हैं , या हम कह सकते हैं की Operators को कोई process / या operation को perform करने के लिए use करते हैं।

Python Operator

For Example -

Copy Fullscreen Close Fullscreen Run
x = 10
y = 20
print(x+y)

ऊपर दिए गए example में आप देखा सकते हैं कि + (plus sign) Operator define की गयी दो values को add रहा है।


इसी तरह से Python हमें different - different Operators provide कराती है different - different action perform करने के लिए। Python में normally use होने वाले Operators कुछ इस प्रकार हैं -

  1. Arithmetic Operators
  2. Assignment Operators
  3. Comparison Operators
  4. Logical Operators
  5. Identity operators
  6. Membership operators

Note : बाकी languages like PHP , Java , JavaScript की तरह Python increment / decrement operators को support नहीं करता है।

Python Arithmetic Operators

Arithmetic Operators simple calculation में use होने wale Operators होते हैं जैसे Addition , Subtraction etc.

OperatorNameExample Explanation
+Additionx+y
( + ) plus operator uses to add two or more numbers / values
-Subtraction

x-y

 ( -  ) minus  operator uses to substract one  numbers / values from another numbers / values or finds the difference 
/Divisionx / yquotient of x and y with decimal point.
//Flour Divisionx // yquotient of x and y without decimal point
*multiplicationx * yproduct of x and y
%Modulusx % yremainder of operands
**Exponentiationx ** yx raised to the power y

Python Arithmetic Operators Example

Copy Fullscreen Close Fullscreen Run
x = 7
y = 3
print("Addition : ", x+y)
print("Subtraction : ", x-y)
print("Division : ", x/y)
print("Floor Division : ", x//y)
print("Multiplication : ", x*y)
print("Modulus : ", x%y)
print("Exponentiation : ", x**y)
Output
C:\Users\Rahulkumar\Desktop\python>python arithmetic_op.py
Addition :  10
Subtraction :  4
Division :  2.3333333333333335
Floor Division :  2
Multiplication :  21
Modulus :  1
Exponentiation :  343

Python Assignment Operators

Assignment Operator को ( = ) से represent करते हैं , जो कि value को किसी variable में assign करने के लिए use किया जाता है। हालाँकि इसे Arithmetic Operators के साथ भी use करते हैं।

OperatorNameExample Explanation
=Assignx = yvalue of y assigned tox
+=Addition then Assign

x += y

First Add and then assign it to x. (It treats like x = x+y)
-=Subtract then Assign

x -= y

get the difference and assign it to x. (It treats like x = x-y)
/=Divide then assign quotient with decimal point,x /= yquotient of x and y then assign it to x .( It treats like x = x/y )
// =Divide then assign quotient without decimalx //= yIt is same as x = x//y
* =Multiplication then assign the productx *= yproduct of x and y then assign it to x.( It treats like x = x*y )
% =Divide then assign remainderx %= yremainder of operands then assign it to x.( It treats like x = x+%y )

Python Assignment Operators Example

Copy Fullscreen Close Fullscreen Run
x ,y = 7, 3
x += y
print(x)

x,y = 7, 3
x -= y
print(x)

x,y = 7, 3
x /= y
print(x)

x,y = 7, 3
x //= y
print(x)

x,y = 7, 3
x *= y
print(x)
Output
C:\Users\Rahulkumar\Desktop\python>python assignment_op.py
10
4
2.3333333333333335
2
21

Python Comparison Operators

Comparison Operators दी हुई दो values को compare करके Boolean value True / False return करते हैं. Python में Comparison Operators को कुछ इस तरह से use कर सकते हैं।

OperatorNameExample Explanation
==Equalx = = ychecks if x is equal to y.
!=Not equalx != ychecks if x is not equal to y.
<Less thanx < ychecks if x is less than y.
>Greater thanx > ychecks if x is greater than y.
<=Less than or equalx <= ychecks either x is less than or equal to y.
>=Greater than or equalx >= ychecks either x is greater than or equal to y

Python Logical Operators

Logical Operators , एक या एक से अधिक expression के according Boolean value return करते हैं।

OperatorNameExample Explanation
andAndx and yReturns True if Both operands (x and y) are true;
orOr

x or y

Returns True if eitherx or y is true;
notnotnot(x)returns True if either x not true;

Python Identity Operators

जैसा कि name से ही पता चलता है कि किसी variable की identity check हो रही है , for - example : एक variable int type का है या नहीं इसके लिए हम is / is not का use कर सकते हैं।

Copy Fullscreen Close Fullscreen Run
a = 10
b = '10'
print(type(a) is float)
print(type(a) is int)
print(type(b) is int)
print(type(b) is not int)
Output
C:\Users\Rahulkumar\Desktop\python>python identity_op.py
False
True
False
True

Python Membership Operators

membership operators का use किसी single element की किसी sequence (like : list , set , dictionary) में existency check करने के लिए use किया जाता है , जैसे हमें ये check करना हो कि किसी list में कोई particular element है या नहीं।

Python Membership Operator Example
Copy Fullscreen Close Fullscreen Run
l = [12,45,567,67]
s = {23,45,67,677}
t = (32,4,54656,67)
print(12 in l)
print(120 not in l)

print(23 in s)
print(120 in s)

print(23 in t)
print(32 in t)
Output
C:\Users\Rahulkumar\Desktop\python>python membership_op.py
True
True
True
False
False
True

example में तीन variables (list , set और tuple) लिए गएँ हैं इनमे simply check किया है कि कोई particular element उनमे exist करता है या नहीं।

अगर आप list , set और tuple etc के बारे में नहीं जानते तो कोई बात नहीं आगे आप इन्ही के बारे में अच्छे से पढ़ेंगे।


I Hope, अब आप Python में use होने वाले operators के बारे में अच्छे से समझ गए होंगे।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers