• Day4:the basic use of Set,%,Format and function


    #****Summary of data type and variable*****

    """

    1:

    Can be changed or not:

        can :list and dict   :the same ID

        no  :string ,int and tuple: The different ID

    2:

    Access sequence:

         1: direct access: number(int)

         2: sequence: list,tuple,string

         3: mapping: dict(no sequence and faster than the sequence but use more memory)

    3:

    The type of saving the charameters:

        1: container:list,tuple,dict

        2: atom:int and string

    """


    #**************set******************

    """

    1: Consists of different characters (unrepeatable)

    2: No sequence

    3: Consists of unchangeable types(int,string and tuple)

    s = {1,2,235,6,7,8,8,8}

    print(s)

    # >>>>>{1, 2, 6, 7, 8, 235}

    # unrepeatable and no sequence

    s = {. }

    # >>>>>>copy

        s1 = s.copy()

    # >>>>>>Delete

    # Random delete:

        s.pop()

    # Apponint delete:

        s.remove('alex') >>>> report wrong if it wasn't exist

        s.discard('ascv') >>>>won't report

    # >>>>>>Intersection:

    p_s = ['alex','phjh','ftgc','alex']

    l_s = ['phjh','ftgc','ujhgd']

    p_s = set(p_s)

    l_s = set(l_s)

    # print(p_s,l_s)

    # print(p_s.intersection(l_s))

    # print(p_s&l_s)

    # >>>>>>union: 

    # print(p_s.union(l_ts))

    # print(p_s|l_s)

    # >>>>>>difference

    print(p_s-l_s)

    print(l_s-p_s)

    print(p_s.difference(l_s))

    print(l_s.difference(p_s))

    # >>>>>>symmetric_difference

    print(l_s.symmetric_difference(p_s))

    print(p_s^l_s)

    # >>>>>>difference_update

    # p_s.difference_update(l_s)

    p_s = p_s-l_s

    print(p_s)

    # >>>>>>intersection_update

     # >>>>>>symmetric_difference update

    l_s.symmetric_difference_update(p_s)

    print(l_s)

    # >>>>>>symmetric_difference update

    p_s.symmetric_difference_update(l_s)

    print(p_s)

    # >>>>>>isdisjoint

    print(l_s.isdisjoint(p_s))

    # >>>>>>issubset: s1 <= s2

    print(l_s.issubset(p_s))

    # >>>>>>issuperset: s1 <= s2

    print(l_s.issuperset(p_s))

    """

    # >>>>>>update :can update multiple values and update the type which is iterable

    s1 = {1,2}

    s2 = {1,2,3}

    s1.update(s2)

    # = print(s1.union(s2)) but this sentence the s1 valus does't change

    s1.update((3,4,5))

    # >>>>>>add :can just update single  value and update the type which is iterable

    s2.add((3,4,5))

    # >>>>>{1, 2, 3, (3, 4, 5)}

    # s2.add(3,4,5)

    # >>>>>report wrong

    print(s1,s2)

    # >>>>>>frozenset : can't be changed can't add/opp/remove

    s = frozenset('hello')

    print(s)

    # use set to extact the repeated character but the sequence may be changed

    s = ['alex','alex','adhx']

    print(list(set(s)))

    # >>>>*******use % to stched the string******

    """

    s = 'My name is %s and I am %d yeas old' %('zxver',26)

    s = 'My name is %(name)s and my age is %(age)d yeas old' %{'name':'zxver','age':26}

    print(s)

    # %s can be used for any type

    # %.s can sliced the character

    s2 = 'the string is %.3s' %'asdfg'

    print(s2)

    # %d can only be used for int

    # better to use the corresponding type cause it can save the memory

    s1 = 'My name is %s and I am %s yeas old' %('zxver',[])

    print(s1)

    # s = 'the number is %.2f' %99.47377262626

    # add a %

    s = 'percent %.2f %%' %99.47377262626

    print(s) 

    s = "i am %.(pp)2f" %{"pp":99.47377262626,}

    print(s)

    # >>>>>>>justified signal and add color

    # + Right justified - Left justified

    s = 'My name is 33[43;1m%(name)+20s33[0m and my age is %(age)d yeas old' %{'name':'zxver','age':26}

    print(s)

    """

    # >>>>>>print the group 

    print('root','pwd','0','0',sep=':')

    # >>>>>*******format the string********

    """

    s = ' I am {} ,my name is {} ,{}'.format('zxver',19,'alex')

    print(s)

    # can set the extact sequence

    s = ' I am {2} my name is {1} ,{0}'.format('zxver',19,'alex')

    # tuple:

    s = ' I am {name} my age is {age} '.format(name='zxver',age=19)

    print(s)

    # dict==: must add'**'

    s = ' I am {name} my age is {age} '.format(**{'name':'zxver','age':19})

    print(s)

    s = ' I am {0[0]},my age is {0[1]} really{0[2]}'.format([1,2,3],[5,6,7])

    print(s)

    s = ' I am {:s} my age is {:d} really{:f}'.format('zxver',19,56.8828)

    print(s)

    s = ' I am {:s} my age is {:d} '.format(*['alex',26])

    # take one * when use list type

    print(s)

    """

    # >>>>>>The format of binary/octal/decimal/hexadecimal and percent

    s = ' the number is :{:b},{:o},{:d},{:x},{:X},{:%}'.format(15,15,15,15,15,15.82899391)

    print(s)

    #*************function*****************

    def test(x):  # can include the parameter or not

        """.  """ # write the function

        y = 3 * x + 1

        return y

    a = test(3)

    print(a)

    # return summary

    """

    value =0:none

    value =1:object

    value >1:tuple

    # *******1:the two types of parameter*****

    def cal(x,y):  # formal parameters,just when call it use memory

        '''. '''

        res = x**y 

        return res

    c = cal(a,b)        # argument

    print(c)

    # >>>>>>2: position parameter:must be correspondent and the strict number require

    def test(x,y,z):

        print(x)

        print(y)

        print(z)

    # test(1,2,3)

    test(y=2,x=5,z=8)

    # 3:***************key words parameter and ***Position parameter must be the left side of key words parameter

     # Default parameter

    def handle(x,y='alex'):

         print(x)

         print(y)

    handle('zxver')

    handle('zxver','list')

    def install(func1=false,func2=true,func3=false):

        pass

    # *******4: parameter group: ** means dict,* means list**********

    def test(x,*asig):

        print(x)

        print(asig)

        print(asig[0]['name'])

    # test(1,2,3,4,5)

    # test(1,{'name':'alex','hobby':'play'})

    # test(1,[3,4,68,89])

    test(1,*[3,4,68,89])

    def test(x,**kwedh):

        print(x)

        print(kwedh)

    test(1,a=1,b='d')

    """

    def test(x,*asdf,**ghjk):

        print(x)

        print(asdf,asdf[-1])

        #print(ghjk,ghjk['b'])

        print(ghjk,ghjk.get('b'))

    # test(1,2,3,4,5,a=2,b=3)

    test(1,*[3,4,5],**{'b':1})

  • 相关阅读:
    表变量与临时表
    表单提交原理
    C_Free引用链接库
    禁用ViewState(转)
    jquery设置元素的readonly和disabled
    WebService经验分享
    如何给GridView添加滚动条 收藏
    bcp+Sql语句抽取数据导出
    List<T>的排序
    AppDomain与动态加载程序集
  • 原文地址:https://www.cnblogs.com/zxver/p/11964346.html
Copyright © 2020-2023  润新知