# assignment of data structures in python
x=1
y=10.01
z='saket'
print ('x=',x,'\ny=',y,'\nz=',z,'\n')
a=b=c=1
print ('a=',a,'\nb=',b,'\nc=',c,'\n')
a,b,c=1,10.59,'parab'
print ('a=',a,'\nb=',b,'\nc=',c)
del a
#print (a); this will cause error
a='This is world of Python!'; # string
print (a,'\n');
print (a[0],'\n');
print (a[2:6],'\n');
print (a[2:],'\n');
print (a*3,'\n');
list=[1,2,'saket',90,'Python',45,721] # list
print (list[0],'\n')
print (list[1:3],'\n')
print (list[2:],'\n')
print (list*2,'\n')
list[1]='parab'
print (list[1],'\n')
tuple=(1,2,3,4,5,'saket');
print (tuple[0],'\n')
print (tuple[1:3],'\n')
#tuple[1]=10; this will cause error as tuple cannot be changed
print (oct(tuple[2]))
dict={} # dictonary
dict['apple']=3
dict['oranges']=9
dict['type']='fruits'
dict[1]='batch 1'
print (dict[1],'\n');
print (dict['type'],'\n');
print (dict.keys())
print (dict.values())
This snippet helps you to write your first python program along with basic introduction to the data structures. You will know how to initialize various variables and access them. Cheers!
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.