Python学习笔记--列表

Welcome to JS/Linux (x86)

 

Use 'vflogin username' to connect to your account.

You can create a new account at https://vfsync.org/signup .

Use 'export_file filename' to export a file to your computer.

Imported files are written to the home directory.

 

[root@localhost ~]# python

Python 2.7.11 (default, May 24 2017, 22:33:10)

[GCC 6.1.0] on linux2

Type "help", "copyright", "credits" or "license" for more information.

列表赋值

>>> aList=[123,'abc',4.56,['inner','list'],7-9j]

>>> aList

[123, 'abc', 4.5599999999999996, ['inner', 'list'], (7-9j)]

>>> anotherList=[None,'something to seee here']

>>> aList

[123, 'abc', 4.5599999999999996, ['inner', 'list'], (7-9j)]

>>> anotherList

[None, 'something to seee here']

>>> print anotherList

[None, 'something to seee here']

访问列表中的值

>>> aList[0]

123

>>> aList[1-3]

['inner', 'list']

>>> aList[1]

'abc'

>>> aList[1-2]

(7-9j)

>>> aList[1:2]

['abc']

>>> aList[1:3]

['abc', 4.5599999999999996]

>>>

>>> aList[1:4]

['abc', 4.5599999999999996, ['inner', 'list']]

>>> aList[:4]

[123, 'abc', 4.5599999999999996, ['inner', 'list']]

>>> aList[3][1]

'list'

>>> aList[3][2]

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

IndexError: list index out of range

>>> aList[3][0]

'inner'

更新列表

>>> aList[2]='float replacer'

>>> aList[2]

'float replacer'

>>> aList

[123, 'abc', 'float replacer', ['inner', 'list'], (7-9j)]

>>> aList.append("hi,i'm new here")

>>> aList

[123, 'abc', 'float replacer', ['inner', 'list'], (7-9j), "hi,i'm new here"]

>>> aList.append(hi,i'm new here)

  File "<stdin>", line 1

    aList.append(hi,i'm new here)

                                ^

SyntaxError: EOL while scanning string literal

>>>

>>> del aList[0]

>>> aList

['abc', 'float replacer', ['inner', 'list'], (7-9j), "hi,i'm new here"]

>>> aList.remove('abc')

>>> aList

['float replacer', ['inner', 'list'], (7-9j), "hi,i'm new here"]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值