python笔记2018年3月28日

发布时间:2019-09-14 09:45:54编辑:auto阅读(1743)

    '''集合'''

    s = {3,2,3,5}

    print(len(s))

    s.add(6)

    print(s)

    #

    '''列表'''

    m =[1,3,4,1]

    print(len(m))

    m.append(7)

    print(m)

    #

    '''字典'''

    d = {'dogs':5, 'cats':4}

    print(len(d))

    print(d["dogs"])

    d["pigs"]=7

    print(d.keys())

    print(d.values())

    from numpy import array
    '''数组Numpy Arrays'''
    a =array([1,2,3,4])
    b = a+2
    print(a)
    print(b)

    '''循环loop'''
    line = '1,3,3,4,5'
    l = sum([int(field) for field in line.split(',')])
    print(l)

关键字