美文网首页
python3 学习

python3 学习

作者: ouis | 来源:发表于2016-05-19 23:23 被阅读57次

    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,)

    相关文章

      网友评论

          本文标题:python3 学习

          本文链接:https://www.haomeiwen.com/subject/ljwgrttx.html