• python 序列结构-列表,元组,字典,字符串,集合


    列表

    """
    name_list.__add__(          name_list.__getslice__(     name_list.__new__(          name_list.append(
    name_list.__class__(        name_list.__gt__(           name_list.__reduce__(       name_list.count(
    name_list.__contains__(     name_list.__hash__          name_list.__reduce_ex__(    name_list.extend(
    name_list.__delattr__(      name_list.__iadd__(         name_list.__repr__(         name_list.index(
    name_list.__delitem__(      name_list.__imul__(         name_list.__reversed__(     name_list.insert(
    name_list.__delslice__(     name_list.__init__(         name_list.__rmul__(         name_list.pop(
    name_list.__doc__           name_list.__iter__(         name_list.__setattr__(      name_list.remove(
    name_list.__eq__(           name_list.__le__(           name_list.__setitem__(      name_list.reverse(
    name_list.__format__(       name_list.__len__(          name_list.__setslice__(     name_list.sort(
    name_list.__ge__(           name_list.__lt__(           name_list.__sizeof__(
    name_list.__getattribute__( name_list.__mul__(          name_list.__str__(
    name_list.__getitem__(      name_list.__ne__(           name_list.__subclasshook__(
    """
    name_list = ["张三","刘大"]
    print( name_list.index("刘大"))
    
    name_list.append("李四")
    print name_list

    列表的append的方法,返回值是None 意味着没有新列表产生,就地修改
    In [1]: alist = [1,4,6,90,11,2,3,3,89]
    In [2]: a = alist.append(10)
    In [3]: print(a)
    None
    In [4]: type(a)
    Out[4]: NoneType
    In [5]: alist
    Out[5]: [1, 4, 6, 90, 11, 2, 3, 3, 89, 10]
    
    
    



    name_list.insert(
    1,"王五") print name_list a_list = ["李二","赵六"] name_list.extend(a_list) print name_list name_list.remove("李二") #会把列表中第一次出现的这个值 print name_list name_list.pop() print name_list name_list.pop(2) print name_list del name_list[1] #变量从内存中删除 print name_list len_str = len(name_list) print("列表中包含%d个元素" %len_str) count = name_list.count("李四") print("列表中李四出现了%d次" %count) name_list.sort() #按正序排列 print name_list name_list.sort(reverse=True) #按正序排列 print name_list print("-----") name_list.reverse() #将列表反转 print name_list

    元组

    >>> empty_tuple = ()
    >>> type(empty_tuple)
    <type 'tuple'>
    >>>
    >>> single_tuple = (1)
    >>> type(single_tuple)
    <type 'int'>
    >>> single_tuple1 = (1,)
    >>> type(single_tuple1)
    <type 'tuple'>
  • 相关阅读:
    200斤的甄子丹还是这么灵活能打欢乐,拯救无聊就靠他了
    redis 发布与订阅
    洛谷P2294 [HNOI2005]狡猾的商人
    洛谷P2294 [HNOI2005]狡猾的商人
    崛起于Springboot2.X之开发拦截器(21)
    pfSense®2.4.4发布后,原pfSense 黄金会员的服务将免费使用!
    pfSense®2.4.4发布后,原pfSense 黄金会员的服务将免费使用!
    pfSense®2.4.4发布后,原pfSense 黄金会员的服务将免费使用!
    pfSense®2.4.4发布后,原pfSense 黄金会员的服务将免费使用!
    Openssh
  • 原文地址:https://www.cnblogs.com/carlos-mm/p/7985321.html
Copyright © 2020-2023  润新知