列表 、 元组
列表是我们最常用的数据类型之一,通过列表可以对数据实现最方便的存储、修改等操作
# -Author - "win"View Code
names = ["zhangyining ","wangmeng ","lixiaoxia","dingjunhui","liuguoliang ","malong ","wanghao "]
print(names )
print(names[0])
print(names[1:4])
print(names[::2])
print(names[:2])
names.append("liangxiaoting")
print(names)
names.insert(1,"lixiaoxu")
print(names)
names[2] = "yaoming"
print(names)
names.append("张兆旭")
print(names)
names.remove("张兆旭")
print(names)
names.copy()
['zhangyining ', 'wangmeng ', 'lixiaoxia', 'dingjunhui', 'liuguoliang ', 'malong ', 'wanghao ']
zhangyining
['wangmeng ', 'lixiaoxia', 'dingjunhui']
['zhangyining ', 'lixiaoxia', 'liuguoliang ', 'wanghao ']
['zhangyining ', 'wangmeng ']
['zhangyining ', 'wangmeng ', 'lixiaoxia', 'dingjunhui', 'liuguoliang ', 'malong ', 'wanghao ', 'liangxiaoting']
['zhangyining ', 'lixiaoxu', 'wangmeng ', 'lixiaoxia', 'dingjunhui', 'liuguoliang ', 'malong ', 'wanghao ', 'liangxiaoting']
['zhangyining ', 'lixiaoxu', 'yaoming', 'lixiaoxia', 'dingjunhui', 'liuguoliang ', 'malong ', 'wanghao ', 'liangxiaoting']
['zhangyining ', 'lixiaoxu', 'yaoming', 'lixiaoxia', 'dingjunhui', 'liuguoliang ', 'malong ', 'wanghao ', 'liangxiaoting', '张兆旭']
['zhangyining ', 'lixiaoxu', 'yaoming', 'lixiaoxia', 'dingjunhui', 'liuguoliang ', 'malong ', 'wanghao ', 'liangxiaoting']
元组其实跟列表差不多,也是存一组数,只不是它一旦创建,便不能再修改,所以又叫只读列表
names = ("yaoming","sunyue","yijianlian","sunwei","zhufangyu")
print(names)
('yaoming', 'sunyue', 'yijianlian', 'sunwei', 'zhufangyu')
names.count("yaoming")
print(names.count("yaoming"))
names.index("yaoming")
print(names.index("yaoming"))
1
0