Apply for Zend Framework Certification Training

Python





Python Operators

#Arithmetic operators

#Assignment operators

#Comparison operators

#Logical operators

#Identity operators

#Membership operators

#Bitwise operators


 

Arithmetic operators

x= 103; y= 20;

z= x+y;

print(z)

z= x-y;

print(z)

z= x*y;

print(z)

z= x/y;

print(z)

z= x%y;

print(z)

z= x**y;

print(z)

 

Assignment Operators

a = 101;

print(a)

a= a+5;

a+=5

print(a)

a= a-5;

print(a)

a*=5

print(a)

Comparison Operators

a = 20;

b= 20;

if(a==b):

    print("a is equal to b");

else:

    print("a is not equal to b");


 

if(a!=b):

    print("a is not equal to b");

else:

    print("a is  equal to b");

#logical operator

 

#Logical operators are used to combine conditional statements:

# and

# Returns True if both statements are true


 

x=10;

y=30;

#print(x>5 and y>200)

 

#Or

#Returns True if one of the statements is true

#print(x>5 or y>200)

#not

#Reverse the result, returns False if the result is true

print (not(x>5 and y>20))

Identity Operator

#Identity operators are used to compare the objects,

# not if they are equal, but if they are actually the same object,

# with the same memory location:

#is

x=['english','hindi']

y=['english','hindi']

z = x;

print(x is z)

print(x==y)

print(z)

print(x)

f="10";

g="10";

q=f;

print(f is g)

print(f==g)

#is not

#Returns True if both variables are not the same object

 

print(x is not z)

print (x != z)

Membership Operators

in

#Returns True if a sequence with the specified value is present in the object

x=['english','hindi'];

print('hindi' in x)

 

# not in

#Returns True if a sequence with the specified value is not present in the object

 

print('hindi' not in x)

print('hindi1' not in x)

 

#Bit wise operator

#bitwise operator

#AND

print(6&3)

#110        6

#010

#011        3

 

#110

#011

#-----

#   010     2

 

# 1000 

# 1001

# 1010

# 1100

#OR

print(6|3)

 

#110

#011

#-----

#   111     7

#XOR

print(6|3)

 

#110

#011

#-----

#   101     5

 

#NOT

~3

# 011

# 100

#Zero fill left shift

#3<<2

#011

#01100  12

# right shift

#0100       4

#0001       1

 

< Variable in python Create table data using tkinter >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top