Professional Documents
Culture Documents
Python Learning
Python Learning
Import math
pi = 3.14
x = 1
y = 2
z = 3
# print(round(pi))- rounding off
# print(math.ceil(pi))- upper value
# print(math.floor(pi))- lower value
# print(abs(pi))- absolute value
# print(pow(pi,2))- power raised to
# print(max(x,y,z))- maximum out of
three values
# print(max(x,y,z,pi))- minimum out of
three values
# print(math.sqrt(pi))- square root of
given value
#print(math.sqrt(34342))- square root
of any number
String Slicing
name = ("Mahadev Rokade")
first_name = name[0:8]-
index[start:end]
last_name = name[8:]- index[start:end]
reversed_name = name[::-1]-
index[start:end:step]
funky_name = name[::2]
print(first_name)
print(last_name)
print(reversed_name)
print(funky_name)
input function
name = input("what is your name:")
age = int(input("what is your age: "))
height = float(input("what is your
height: "))
print("hello"+name)
print("you are"+str(age)+"years old")
print(" and your height
is"+str(height))
slice option
website1 = "http://google.com"
website2 = "http://wikipedia.com"
slice = slice(7,-4)
print(website1[slice])
print(website2[slice])
if statements
age = int(input("How old are you? :"))
logical operators
and, or and not
temp = int(input("what is the
temperature today?: "))
while len(name) == 0:
name = input(" what is your name:")
print (" hello "+str(name))
For loops = is the code which is run for the limited time
for i in range(50,100+1,2):
print(i)
for i in range(0,10):
print(i)
import time
for seconds in range (10,0,-1):
print(seconds)
time.sleep(1)
print("Happy New year")