#使用DocStrings
def printMax(x,y):
x=int(x)#convert to integers,if possible
y=int(y)
if x>y:
print x,'is maximum'
else:
print y,'is maximum'
printMax(3,5)
print printMax
#使用sys模块
import sys
print 'The command line arguments are:'
for i in sys.argv:
print i
print '\n\n the pythonpath is',sys.path,'\n'
#使用模块_name_
if __name__=='__main__':
print 'This program is being run by itself'
else:
print 'I am being imported from another module'
#如何创建你自己的模块
import mymodule
mymodule.sayhi()
print 'Version',mymodule.version
#使用dir函数
import sys
dir(sys) # get list of attributes for sys module
#使用列表
shoplist=['apple','mango','carrot','banana']
print 'I have',len(shoplist),'items to purchase.'
print 'These items are:',
for item in shoplist:
print item,
print '\n I also have to buy rice.'
shoplist.append('rice')
print 'My shoppinglist is now',shoplist
print 'I will sort my list now'
shoplist.sort()
print 'Sorted shopping list is',shoplist
print 'The first item I will buy is',shoplist[0]
olditem=shoplist[0]
del shoplist[0]
print 'I bought the',olditem
print 'My shopping list is now',shoplist
#使用元组
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 zoo is',len(new_zoo)
print 'All naimals 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]
#使用元组输出
age=22
name='Swaroop'
print '%s is %d years old'%(name,age)
print 'Why is %s playing with that python?'%name