Python Programs
Python Programs
print("hello","world")
2. type of variable
a=5
b="john"
print("my name is",b);
print(type(b)) # will give datatype of variable
3. Literals
4. expressions
5. compound operator
#compound operator
x=5
x+=1
print(x)
#comparison operator
a=3
b=4
c=a<b
print(c)
8. list
# list datatype
list=[]
list1=[1,2,3,4]
list2=["neha",1,2.0,5,6,7,8]
print(list2[1:5]) # slice operator
print(list2[-1]) # print last element
list1.append(0) # add element in list
print(list1)
9. Tuple
#tuple datatype
tuple1=('a',1,2,"hello")
print(tuple1)
print(tuple1[1:])
print(tuple1[2])
10. Set
# set datatypes
set1={8,7,4,9,5}
set2={3,2,6,1}
print(set)
print("union of set is",set1.union(set2))
11. For-loop
Table of 5
# print table of 5
for var in range(1,11):
mul=5*var
print("5*%d="%var,mul)
Factorial of a number
for i in "hello":
if(i=='e'):
#continue
break
print(i)
print(i)