Python chapter 2

input function

a = input ("enter your name:")
a = int (a) # convert a to an integer if possible
print (type(a))

Operators


a = 3
b = 4
# arithmetic operators 
print ("the value of 3+4 is ", 3+4)
print ("the value of 3-4 is ", 3-4)
print ("the value of 3*4 is ", 3*4)
print ("the value of 3/4 is ", 3/4)
# Assignment operators 
a = 34 
a -= 2
a *= 2
a /= 2
print (a)
# Comparison operators
b = (14>7)
b = (14<=7)
b = (14>=7)
b = (14==7)
b = (14!=7) , #14 is not equal to 7 
print (b)

# Logical operators
bool1 = True
bool2 = False
print ("the value of bool1 and bool2 is", (bool1 and bool2))
print ("the value of bool1 and bool2 is", (bool1 or bool2))
print ("the value of not bool2 is", (not bool2))

Type casting


# string to int
a = "345"
a = int(a)
print (type(a))
print (a + 5)

# string to float
a = "345"
a = float(a)
print (type(a))
print (a + 5)

# int to string
a = 345
a = str(a)
print (type(a))
print (a + "ram" )

Variable


a = "Onam" 
b = 345
c = 45.32 
d = False
e = None

# printing the variable
print (a)
print (b)
print (c)
print (d)
print (e)

# printing the type of variable
print (type(a))
print (type(b))
print (type(c))
print (type(d))
print (type(e))

Comments

Popular posts from this blog

Python chapter 3

Login Page design using Html and CSS only