zoukankan      html  css  js  c++  java
  • D14 集合set 函数def

    把 字符串  元祖 变成集合的方法   因为列表是可变的所以不能变为集合

     # s=set('hello')
    # print(s)
    #
    # s=set(['alex','alex','sb'])
    # print(s)

    # s={1,2,3,4,5,6}

    #添加
    # s.add('s')
    # s.add('3')
    # s.add(3)
    # print(s)

    # s.clear()
    # print(s)

    # s1=s.copy()

    s={'sb',1,2,3,4,5,6}
    #随机删
    # s.pop()

    #指定删除
    # s.remove('sb')
    # s.remove('hellol') #删除元素不存在会报错
    # s.discard('sbbbb')#删除元素不存在不会报错
    # print(s)


    # python_l=['lcg','szw','zjw','lcg']
    # linux_l=['lcg','szw','sb']
    # p_s=set(python_l)
    # l_s=set(linux_l)
    # #求交集
    # print(p_s,l_s)
    # print(p_s.intersection(l_s))
    # print(p_s&l_s)
    # #求并集
    # print(p_s.union(l_s))
    # print(p_s|l_s)
    # #差集
    # print('差集',p_s-l_s)
    # print(p_s.difference(l_s))
    # print('差集',l_s-p_s)
    # print(l_s.difference(p_s))

    #交叉补集
    # print('交叉补集',p_s.symmetric_difference(l_s))
    # print('交叉补集',p_s^l_s)

    python_l=['lcg','szw','zjw','lcg']
    linux_l=['lcg','szw','sb']
    p_s=set(python_l)
    l_s=set(linux_l)
    print(p_s,l_s)
    # print('差集',p_s-l_s)
    # p_s=p_s-l_s
    p_s.difference_update(l_s)
    print(p_s)

    # s1={1,2}
    # s2={2,3,5}
    # print(s1.isdisjoint(s2))

    s1={1,2}
    s2={1,2,3}
    print(s1.issubset(s2))#s1 是s2 的子集
    print(s2.issubset(s1))#False

    print(s2.issuperset(s1))#s1 是s2 的父集

    s1={1,2}
    s2={1,2,3}
    # s1.update(s2) #更新多个值

    # s1.add(1,2,3,4) #更新一个值
    # s1.union(s2) #不更新

    print(s1)

     函数def

    def  函数的格式

    test  函数的名称

    def text(x, y, z):
        y = x * 2 + 1
        z = 8 + y
        x = z + 9
        print(x,y,z)
        return (x,y,z)
    
    
    text(4,3,2)
    
    
    text(y=10,x = 3,z=2)

    a = text(2,4,5)
    print(a)

    函数由于 自变量不同而导致因变量不同的正确姿势

    #位置参数,必须一一对应,缺一不行多一也不行
    # test(1,2,3)

    #关键字参数,无须一一对应,缺一不行多一也不行
    # test(y=1,x=3,z=4)

    #位置参数必须在关键字参数左边
    # test(1,y=2,3)#报错
    # test(1,3,y=2)#报错
    # test(1,3,z=2)
    # test(1,3,z=2,y=4)#报错
    # test(z=2,1,3)#报错

    def handle(x, type='mysql'):
        print(x)
        print(type)
    #上面是函数的过程  也叫做形参
    #下面的会占内存空间  也叫实参
    handle(
    'hello')#这个是给函数提供自变量 handle('hello', type='sqlite') # 此时更改了函数

    函数的参数组

    参数组:**字典 *列表

    1   *列表

    def test(x,*args):
        print(x)
        print(args)
    
    
    test(1)
    test(1,2,3,4,5)
    test(1,{'name':'alex'})
    test(1,['x','y','z'])
    test(1,*['x','y','z'])   #前面加了*
    test(1,*('x','y','z'))   #前面加了*

    输出的结果

    1
    ()
    1
    (2, 3, 4, 5)
    1
    ({'name': 'alex'},)
    1
    (['x', 'y', 'z'],)
    1
    ('x', 'y', 'z')
    1
    ('x', 'y', 'z')

    2字典

    def test(x, **kwargs):
        print(x)
        print(kwargs)
    
    
    test(1, y=2, z=3)  # test(1,1,2,2,2,2,2,y=2,z=3)
    #test(1, y=2, z=3, z=3)  # 会报错 :一个参数不能传两个值
  • 相关阅读:
    清除某个数据库的所有数据库连接的存储过程
    IIS的Windows集成身份验证总结
    新项目的页面不要直接从PageBase继承
    安装Win2003 SP1遇到拒绝访问
    ASP.NET2.0站点跨服务器访问Sql Sever 2005 Reporting Service
    当CodeSmith不在时,续……
    Web讯雷导致IIS无法启动的问题
    Intro to eDiscovery in SharePoint, Exchange, and Lync 2013
    微软云平台
    团队开发博客
  • 原文地址:https://www.cnblogs.com/fromlantianwei/p/9294870.html
Copyright © 2011-2022 走看看