1.元组的概念和用法
zoo = ('wolf','elephant','penguin')
print ('Number of animals in the zoo is',len(zoo))new_zoo = ('monkey','dolphin',zoo)
print ('Number of animals in the new zoo is ', len(new_zoo))print ('All animals in new zoo are', new_zoo)print ('Animals brought from old zoo are ', new_zoo[2])print ('Last animal brought from old zoo is ',new_zoo[2][2])2.百分号取元组数据
age = 22
name = 'Swaroop'print ('%s is %d years old'%(name,age))
print ('Why is %s playing with that python?' % name)3.字典的用法
ab = { 'Swaroop' :'Swaroopch@byteofpython.info',
'Larry' :'Larry@wall.org', 'Matsumoto' :'matz@ruby-lang.org', 'Spammer' :'spammer@hotmail.com'}print ("Swaroop's address is %s" %ab['Swaroop'])4.列表用法
shoplist = ['apple' , 'mango' , 'carrot' , 'banana']
print ('Item 0 is ' , shoplist[0])print ('Item 3 is ' , shoplist[3])print ('Item -1 is ' , shoplist [-1])print ('Item 1 to 3 is ', shoplist[1:3])
print ('Item 2 to end is ', shoplist [2:])print ('Item 1 to -1 is ' , shoplist [1:-1])print ('Item start to end is ' , shoplist [:])name = 'swaroop'
print ('characters 1 to 3 is ' , name[1:3])print ('characters 2 to end is ',name[2:])print ('characters 1 to -1 is ' , name[1:-1])print ('characters start to end is',name[:])