字符串、列表和元组的相同之处
运算符方面
Python 表达式(以列表为例)结果描述
len([1, 2, 3])3长度[1, 2, 3] + [4, 5, 6][1, 2, 3, 4, 5, 6]组合[‘Hi!’] * 4[‘Hi!’, ‘Hi!’, ‘Hi!’, ‘Hi!’]重复3 in [1, 2, 3]True元素是否存在于列表中for x in [1, 2, 3]: print(x, end=" ")1 2 3迭代
索引、截取
L=[‘Google’, ‘Baidu’, ‘Taobao’]
Python 表达式(以列表为例)结果描述
L[2]‘Taobao’读取第三个元素L[-2]‘Baidu’从右侧开始读取倒数第二个元素: count from the rightL[1:][‘Baidu’, ‘Taobao’]输出从第二个元素开始后的所有元素
函数
list可以是字符串、列表和元组
序号函数
1len(list)元素个数2max(list)返回元素最大值3min(list) 返回元素最小值
字符串、列表和元组的区别
字符串列表元组
增jion()append(),extend(),insert()不能增删strip()pop,remove,del,clear不能删改replace()可直接通过索引改不能改查find()、index()、索引、切片、遍历索引、切片、遍历、index()索引、切片、遍历