zoukankan      html  css  js  c++  java
  • python练习(续)

    #使用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 '
    
     the pythonpath is',sys.path,'
    '
    
    #使用模块_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 '
     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
  • 相关阅读:
    需求规格说明书
    需求规格说明书模板0.2版本
    需求规格说明书模板0.1版本
    万事开头难,团队一起盘!!
    工程开始了!(2019-03-04)
    SpringBoot RESTful API返回统一数据格式还不懂?
    Springboot读取配置文件中的属性
    java本地缓存的使用
    解决github访问不了和慢的问题2021-06-27
    Oracle DDL
  • 原文地址:https://www.cnblogs.com/ilxx1988/p/3334044.html
Copyright © 2011-2022 走看看