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
  • 相关阅读:
    java时间戳转换日期 和 日期转换时间戳
    通过blob文件导出下载成Excel文件
    三元表达式进化
    Vue切换组件实现返回后不重置数据,保留历史设置操作
    vue 下载文件
    ide打断点,跑到某一行代码,再执行的方法
    Java操作终端的方法
    前端下载本地文件的方法
    java 读取本地json文件
    js 时间戳转换
  • 原文地址:https://www.cnblogs.com/ilxx1988/p/3334044.html
Copyright © 2011-2022 走看看