zoukankan      html  css  js  c++  java
  • 2018.3.14

    #一组例子
    def demo (newitem,old=[]):
        old.append(newitem)
        return old
    
    print(demo('5',[1,2,3,4]))
    print(demo('aaa',['a','b']))
    print(demo('a'))
    #此处会出现意料之外的情况
    print(demo('b'))
    
    
    def demoo(newitem,old=None):
        if old==None:
            old=[]
        old.append(newitem)
        return old
    
    print(demoo('5',[1,2,3,4]))
    print(demoo('aaa',['a','b']))
    print(demoo('a'))
    print(demoo('b'))
    #可变长度参数
    def demo(**p):
        for item in p.items():
            print(item)
    demo(x=1,y=3,z=5)
    
    def dem(*p):
        for item in p:
            print(item)
    dem('q',3,5.4)
    
    E:Pythonpython.exe E:/All_Code/python/T_text/text.py
    ('x', 1)
    ('y', 3)
    ('z', 5)
    q
    3
    5.4
    f = lambda x,y,z:x+y+z
    print(f(2,3,4))
    print(f('a','r','f'))
    
    g = lambda x,y=33,z=1:x+y+z
    print(g(2,5,5))
    print(g(2))
    
    L=[(lambda x:x**2),lambda x:x**3,lambda x:x**4]
    print(L[0](2),L[2](2))
    import random
    def demo(lst):
        m = min(lst)
        result = (m,)
        for index,value in enumerate(lst):
            if value == m:
                result += (index,)
        return result
    x = [random.randint(1,20) for i in range(50)]
    print(x)
    print(demo(x))
    
    #杨辉三角
    def demo1(t):
        print([1])
        print([1,1])
        line = [1,1]
        for i in range(2,t):
            r=[]
            for j in range(0,len(line)-1):
                r.append(line[j]+line[j+1])
            line = [1]+r+[1]
            print(line)
    demo1(10)
    
    E:Pythonpython.exe E:/All_Code/python/T_text/text.py
    [3, 2, 4, 2, 8, 8, 19, 20, 10, 15, 9, 19, 5, 14, 14, 13, 2, 2, 1, 17, 13, 18, 17, 4, 9, 4, 6, 16, 8, 7, 7, 7, 
    4, 15, 12, 11, 18, 8, 10, 15, 7, 2, 3, 4, 10, 11, 17, 16, 18, 3] (1, 18) [1] [1, 1] [1, 2, 1] [1, 3, 3, 1] [1, 4, 6, 4, 1] [1, 5, 10, 10, 5, 1] [1, 6, 15, 20, 15, 6, 1] [1, 7, 21, 35, 35, 21, 7, 1] [1, 8, 28, 56, 70, 56, 28, 8, 1] [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]
  • 相关阅读:
    匹配session
    Jdk1.8+Eclipse+MySql+Tomcat开发Java应用的环境搭建
    MySQL忘记密码怎么办
    MyBatis框架Maven资源
    MyBatis核心配置文件模版
    MyBatis执行过程显示SQL语句的log4j配置
    MyBatis实体类映射文件模板
    Mybatis 学习-4
    Spring Boot + Swagger
    Spring Boot + Swagger
  • 原文地址:https://www.cnblogs.com/tenjl-exv/p/8568592.html
Copyright © 2011-2022 走看看