其他分享
首页 > 其他分享> > 005_del_len_list

005_del_len_list

作者:互联网

 

"""
目录: 
    一 list
    二 del
    三 len
"""

 


一 list

if __name__ == '__main__':
    list1 = list(range(10))
    print(list1)
    
    aTuple = (123, 'Google', 'Runoob', 'Taobao')
    list1 = list(aTuple)
    print("list: ", list1)

    str = "Hello World"
    list2 = list(str)
    print("list: ", list2)

'''
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list:  [123, 'Google', 'Runoob', 'Taobao']
list:  ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']
'''

 

 

二 del

# list
if __name__ == '__main__':
    a = [-1, 1, 66.25, 333, 333, 1234.5]
    print(a)

    del a[0]
    print(a)

    del a[3:5]
    print(a)

    del a
    print(a)    # NameError: name 'a' is not defined

'''
[-1, 1, 66.25, 333, 333, 1234.5]
[1, 66.25, 333, 333, 1234.5]
[1, 66.25, 333]
NameError: name 'a' is not defined
'''

 

# del
if __name__ == '__main__':
    tel = {'jack': 4098, 'sape': 4139}
    print(tel)

    del tel["sape"]
    print(tel)
    
'''
{'jack': 4098, 'sape': 4139}
{'jack': 4098}
'''

 

 

三 len

if __name__ == '__main__':
    a = [-1, 1, 66.25, 333, 333, 1234.5]
    print(len(a))

    tel = {'jack': 4098, 'sape': 4139}
    print(len(tel))

    str = "runoob"
    print(len(str))
    
'''
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list:  [123, 'Google', 'Runoob', 'Taobao']
list:  ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']
'''

 

标签:__,tel,list,333,del,len,print
来源: https://www.cnblogs.com/huafan/p/16466858.html