第三天基础课程

5.5 判断指定某个元素是否在当前列表中

in 在当前的列表中

not in 不在当前的列表中

来进行判断是否在列表中,返回一个布尔值

5.6 列表数据的修改

运用赋值号‘=’进行数据修改

在这里插入图片描述

注意列表的元素修改时不能超过列表下标的最大值

5.7增加元素

append()

def append(self, *args, **kwargs): # real signature unknown
    """ Append object to the end of the list. """
    pass
注意点:
在列表的末尾追加一个元素,如果对象是列表,那就将列表作为一个元素追加

extend()

def extend(self, *args, **kwargs): # real signature unknown
    """ Extend list by appending elements from the iterable. """
    pass
注意点:
extend参数必须是可以迭代的,将元素迭代追加

index()

def index(self, *args, **kwargs): # real signature unknown
    """
    Return first index of value.
    
    Raises ValueError if the value is not present.
    """
    pass
查找元素在列表中索引
查找不到数据会报错

insert()

def insert(self, *args, **kwargs): # real signature unknown
    """ Insert object before index. """
    pass
在列表的索引之前插入元素

5.8 删除数据

pop()

def pop(self, *args, **kwargs): # real signature unknown
    """
    Remove and return item at index (default last).
    
    Raises IndexError if list is empty or index is out of range.
    """
    pass
删除并返回指定的元素(默认从最后开始)
如果列表为空或者索引值超过范围则引发一个Index错误

remove()

def remove(self, *args, **kwargs): # real signature unknown
    """
    Remove first occurrence of value.
    
    Raises ValueError if the value is not present.
    """
    pass
删除第一个出现的值,如果在列表中找不到的值则返回一个Value错误

clear()

def clear(self, *args, **kwargs): # real signature unknown
    """ Remove all items from list. """
    pass
将列表中所有值进行清空,但不会删除列表
del 列表名
del list[-1]删除末位元素
将列表整体删除

del()

将列表删除

reverse()

def reverse(self, *args, **kwargs): # real signature unknown
    """ Reverse *IN PLACE*. """
    pass
将列表进行倒置

5.9 列表转字符串

str1 = ''.join([str(i) for i in list1])


def join(self, ab=None, pq=None, rs=None): # real signature unknown; restored from __doc__
    """
    Concatenate any number of strings.
    
    The string whose method is called is inserted in between each given string.
    The result is returned as a new string.
    
    Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
    """
    pass

5.10 zip()运用

zip()

class zip(object):
    """
    zip(iter1 [,iter2 [...]]) --> zip object
    
    Return a zip object whose .__next__() method returns a tuple where
    the i-th element comes from the i-th iterable argument.  The .__next__()
    method continues until the shortest iterable in the argument sequence
    is exhausted and then it raises StopIteration.
    """
    相同下标的值压缩打包成一个元组组成的迭代器

5.11 enumerate()运用

class enumerate(object):
    """
    Return an enumerate object.
    
      iterable
        an object supporting iteration
    
    The enumerate object yields pairs containing a count (from start, which
    defaults to zero) and a value yielded by the iterable argument.
    
    enumerate is useful for obtaining an indexed list:
        (0, seq[0]), (1, seq[1]), (2, seq[2]), ...
    """
注意点:
返回一个下标和对应的值所组成的元组组成的迭代器
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值