Operators kya hote hai ?


Operators kuch symbols (Ex :- "+, -, *, /") hai jo programming me variables par kuch operations karte hai. Operators ka use calculations ya comparisons karne ke liye hota hai.

Python me mainly 7 types ke operators hote hai :-



1. Arithmetic Operators

Ye operators mathematical calculations karne ke liye use hote hain. Operators: +, -, *, /, %, //, **

OperatorNaamExampleResult
+Addition10 + 313
-Subtraction10 - 37
*Multiplication10 * 330
/Division10 / 33.333...
%Modulus10 % 31
//Floor Division10 // 33
**Exponentiation10 ** 31000

Example 1: Addition, Subtraction, Multiplication aur Division

Python
In [1]:
1
Output

Example 2: Modulus (%), Floor Division (//) aur Exponentiation (**)

Python
In [1]:
1
Output


2. Comparison (Relational) Operators

Ye operators do values ko compare karte hain aur result hamesha True ya False (Boolean) hota hai. Operators: ==, !=, >, <, >=, <=

OperatorMatlabExampleResult
==Equal to5 == 5True
!=Not equal to5 != 3True
>Greater than5 > 3True
<Less than5 < 3False
>=Greater than or equal5 >= 5True
<=Less than or equal5 <= 3False

Example 1: Equal (==) aur Not Equal (!=)

Python
In [1]:
1
Output

Example 2: Greater / Less than Operators

Python
In [1]:
1
Output


3. Assignment Operators

Ye operators variable me value assign karne ke liye use hote hain. = simple assignment hai, baaki shorthand hain jaise +=, -=, *= etc.

OperatorExampleMatlab
=x = 5x me 5 assign karo
+=x += 3x = x + 3
-=x -= 3x = x - 3
*=x *= 3x = x * 3
/=x /= 3x = x / 3
%=x %= 3x = x % 3
//=x //= 3x = x // 3
**=x **= 3x = x ** 3

Example 1: Simple aur Compound Assignment (+=, -=)

Python
In [1]:
1
Output

Example 2: Multiply, Divide aur Power Assignment (*=, /=, **=)

Python
In [1]:
1
Output


4. Logical Operators

Ye operators multiple conditions ko combine karne ke liye use hote hain. Result hamesha True ya False hota hai. Operators: and, or, not

OperatorMatlabExampleResult
andDono conditions True hon tabhi TrueTrue and FalseFalse
orKoi ek condition True ho toh TrueTrue or FalseTrue
notCondition ko ulta kar deta hainot TrueFalse

Example 1: and aur or Operator

Python
In [1]:
1
Output

Example 2: not Operator

Python
In [1]:
1
Output


5. Bitwise Operators

Ye operators binary level par (bits pe) kaam karte hain. Ye advanced programming aur low-level operations me use hote hain. Operators: &, |, ^, ~, <<, >>

OperatorNaamExample (a=5, b=3)Result
&AND5 & 31
|OR5 | 37
^XOR5 ^ 36
~NOT~5-6
<<Left Shift5 << 110
>>Right Shift5 >> 12

Example 1: AND (&), OR (|) aur XOR (^)

Python
In [1]:
1
Output

Example 2: NOT (~), Left Shift (<<) aur Right Shift (>>)

Python
In [1]:
1
Output


6. Membership Operators

Ye operators check karte hain ki koi value sequence me hai ya nahi (jaise list, string, tuple, etc.). Operators: in, not in

OperatorMatlabExampleResult
inValue present hai sequence me"a" in "apple"True
not inValue present nahi hai sequence me"z" not in "apple"True

Example 1: List me "in" operator

Python
In [1]:
1
Output

Example 2: String me "in" operator

Python
In [1]:
1
Output


7. Identity Operators

Ye operators check karte hain ki do variables same memory location ko point kar rahe hain ya nahi. Sirf values nahi, identity (object) compare hoti hai. Operators: is, is not

OperatorMatlabExampleResult
isDono same object hain?a is bTrue / False
is notDono alag objects hain?a is not bTrue / False

Example 1: "is" Operator

Python
In [1]:
1
Output

Example 2: "is not" aur == vs is ka fark

Python
In [1]:
1
Output