python3 学习

2016-05-19  本文已影响57人  ouis

1.首先下载安装python3.5.1(也可自行到官网下载)

2.输出

3.列表list,为有序集合

>>> word = ['one','two','three']  创建list

>>> word  输出list

['one', 'two', 'three']

要访问本例里面元素,索引从0开始,往前往后2位都可以

>>> word[0] 

'one'

>>> word[1]

'two'

>>> word[2]

'three'

>>> word[-1]

'three'

>>> word[-2]

'two'

>>> word

['one', 'two', 'three']

>>> word[-3]

'one'

>>> word.append('four')  增加

>>> word

['one', 'two', 'three', 'four']

>>> word.insert(0,'zero')在哪插入

>>> word

['zero', 'one', 'two', 'three', 'four']

>>> word.pop()删除末尾元素

'four'

>>> word

['zero', 'one', 'two', 'three']

>>> word.pop(0)删除首位元素

'zero'

>>> word

['one', 'two', 'three']

>>> word[2] = 'threeee'替换某位元素

>>> word

['one', 'two', 'threeee']

>>> ver = ['1',1,False]不同类型集合

>>> ver

['1', 1, False]

>>> va = ['1',['1','2'],3]list可以作为元素

>>> va

['1', ['1', '2'], 3]

4.不可变列表(这里指的是指向不可变,word = (1,[1,2])  里面的list里的元素可变),元组tuple,无增删改,定义时元素必须有逗号,否则>>> word = (1)就相当于word = 1 

>>> word = (1,)

>>> word

(1,)

上一篇下一篇

猜你喜欢

热点阅读