一、列表的定义
1. 创建列表
- >>> name = ['gao', 'sam', 'snow', 'jey'] >>> type(name) < type 'list' > >>> name = list(['gao', 'sam', 'snow', 'jey']) # python 3.0 + 会报错 >>> type(name) < type 'list' > >>> name = [] >>> type(name) < type 'list' > >>> name = list() # python 3.0 + 会报错 >>> type(name) < type 'list' >
2. 切片 与字符串类似
- >>> name = ['Sam', 'Jey', 'Snow', 'Amy'] >>> name[2]'Snow' >>> name[1 : ]['Jey', 'Snow', 'Amy'] >>> name[ - 2 : ]['Snow', 'Amy'] >>> name[ - 1 : -3 : -1]['Amy', 'Snow']
python 列表、元组(三)
来源: http://www.bubuko.com/infodetail-2167918.html