问:Python中列表常见的方法有哪些?
答:Python列表定义:按特定顺序排列的元素组成。在Python中,用方括号[]来表示列表,并用逗号来分隔其中的元素。Python列表是编程中很常见的数据类型 。
列表是一种可修改的集合类型,其元素可以是数字、string等基本类型,也可以是列表、元组、字典等集合对象,甚至可以是自定义的类型。其定义方式如下:
>>> nums = [1,2,3,4]
>>> type(nums)
<type 'list'>
>>> print nums
[1, 2, 3, 4]
>>> strs = ["hello","world"]
>>> print strs
['hello', 'world']
>>> lst = [1,"hello",False,nums,strs]
>>> type(lst)
<type 'list'>
>>> print lst
[1, 'hello', False, [1, 2, 3, 4], ['hello', 'world']]
下面我们来看一下列表中有哪些常见的方法:
python培训:http://www.baizhiedu.com/python2019