Introduction of Python
Getting Started with Python
Syntax in Python
Comment in Python
Variables in Python
Data Types in Python
Numbers in Python
Castings in Python
Strings in Python
Boolean in Python
Operators in Python
List in Python
Tuples in Python
Sets in Python
Dictionary in Python
if Else Statement in Python
While Loop in Python
For Loop in Python
Functions in Python
Lamba Function in Python
Arrays in Python
Classes and Objects in Python
Inheritance in Python
Iterators in Python
Scope in Python
Modules in Python
Dates in Python
Math in Python
JSON in Python
RegEx in Python
Try and Except in Python
User Input in Python
String Formatting in Python
List of Python Operators
Operator, Operands ke sath kisi particular operation ko perform karta hai. Python me kai tarah ke operators hote hain jo niche diye gaye groups me lie karte hain:
(1) Logical operators
(2) Identity operators
(3) Arithmetic operators
(4) Assignment operators
(5) Membership operators
(6) Bitwise operators
(7) Comparison operators
Python Logical Operators
and (&)
Return “True”, Jab dono statements true hogi
Eg : a > 5 and a < 7 ; where a = 6
Return “False”, Jab 2 me se koi ek bhi statement False hogi
Eg : a > 5 and a < 7 ; where a = 4
or (|)
Return “True”, Jab dono statements me se koi ek statement bhi true hogi
Eg : a > 5 or a < 7 ; where a = 4
Return “False”, Jab dono statements False hogi
Eg : a > 5 or a < 3 ; where a = 4
not (!)
Kisi bhi result ko reverse karna jaise True ko False aur False ko True
Eg : not(a > 5) ; where a = 6
Result= “False”
not(a > 5) ; where a = 4
Result = “True”
Python Identity Operators
is
Return “True”, Jab dono objects same honge…
Eg :
a = [“Hello”, “Python”]
b = [“Hello”, “Python”]
c = a
print(a is b)
Result= “False” ;
kyuki ‘a’ aur ‘b’ dono objects same nhi hain
print(a is c)
Result= “True” ;
kyuki ‘a’ aur ‘c’ dono objects same hain
is not
Return “True”, Jab dono objects different honge hogi
Eg :
a = [“Hello”, “Python”]
b = [“Hello”, “Python”]
c = a
print(a is not b)
Result= “True” ;
kyuki ‘a’ aur ‘b’ dono objects same nhi hai
print(a is not c)
Result= “False” ;
kyuki ‘a’ aur ‘c’ dono objects same hai
Python Arithmetic Operators
Addition
(+)
Return Added value
Eg : a = b + c
Subtraction (-)
Return Subtracted value
Eg : a = b – c
Multiplication (*)
Return Multiplied value
Eg : a = b * c
Division (/)
Return divided value
Eg : a = b / c
Modulo
(%)
Return remainder after division
Eg : a = b % c
Exponential (**)
Return powered value
Eg : a = b ** c
Floor Division (//)
Return floored value
Eg : a = b // c
agar b = 3.6 aur c = 1.1 tab ‘a’ ki actual value 3.2727 hogi , lekin floor operator iski down side value print karega, jo iss case me 3.0 hai
Python Assignment Operators
=
a = 4
+=
a += b equal to a = a+b
-=
a -= b equal to a = a – b
*=
a *= b equal to a = a*b
/=
a /= b equal to a = a/b
%=
a %= b equal to a = a%b
**=
a **= b equal to a = a ** b
//=
a //= b equal to a = a // b
&=
a &= b equal to a = a & b
|=
a |= b equal to a = a | b
^=
a ^= b equal to a = a ^ b
>>=
a >>= b equal to a = a >> b
<<=
a <<= b equal to a = a <<b
Python Membership Operators
in
Return “True” jab search ki gai value kisi object ke sequence me available hoga…
Example :
y = [“peacock”,”parrot”,”sparrow”]
print(“parrot in y”)
Result : True
not in
Return “True” jab search ki gai value kisi object ke sequence me available nhi hogi…
Example :
y = [“peacock”,”parrot”,”sparrow”]
print(“crow not in y”)
Result : True
Python Bitwise Operators
Bitwise Operators binary numbers ko aapas me compare karta hai…
& (and)
agar comparing bits 1 hai to yah operator sari bits ko 1 par set kar dega
0 & 1 = 0 ; 1 & 0=0
0 & 0 = 0 ; 1 & 1=1
| (or)
yah sirf 0-1 aur 1-1 ke comparison ko 1 par set karega…
0 | 1 = 1 ; 1 | 0=1
0 | 0 = 0 ; 1 | 1=1
^ (xor)
yah sirf 0 aur 1 ke comparison ko 1 par set karega…
0 ^ 1 = 1 ; 1 ^ 0=1
0 ^ 0 = 0 ; 1 ^ 1=0
~ (not)
Yah bits ki value invert kar dega..
~0 = 1 ; ~1 = 0
<< (left shift)
bits ko left shift karega aur right me zero add karta jayega
Ex :
s = 0b00011
t = s << 2
print(t)
Result : 12
12 means ob01100
>> (right shift)
bits ko right shift karega aur left me zero add karta jayega
s = 0b00011
t = s >> 2
print(t)
Result : 0
0 means ob00000
Python Comparison Operators
== equal
a == b ; a aur b ki value same hai
!= not equal
a != b ; a aur b ki value same nhi hai
> greater than
a > b ; a ki value b se badi hai
< less than
a < b ; a ki value b se small hai
>= greater than equal to
a >= b ; a ki value b se badi ya equal hai
<= less than equal to
a <= b ; a ki value b se small ya equal hai