本文摘自php中文网,作者不言,侵删。
这篇文章主要介绍了关于Python 创建空的list,以及append用法讲解,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下Python中list的用法:如何创建list,如何表达list中的元素,如何修改和删除list
运行环境:Python 3.6.2
0.空list的创建:
或者:
1.list中元素的创建和表达
1 2 3 | fruits = [ 'apple' , 'banana' , 'pear' , 'grapes' , 'pineapple' , 'watermelon' ]
fruits[2] #从0开始数起,第三个元素
pear
|
2.list中元素的更改
1 2 3 | fruits[2] = 'tomato'
print (fruits)
[ 'apple' , 'banana' , 'tomato' , 'grapes' , 'pineapple' , 'watermelon' ]
|
3.在list末尾增加更多元素
1 2 3 | fruits.append( 'eggplant' )
print (fruits)
[ 'apple' , 'banana' , 'tomato' , 'grapes' , 'pineapple' , 'watermelon' , 'eggplant' ]
|
阅读剩余部分
相关阅读 >>
Python如何实现单例模式
Python文件的读写及文件字符编码设置方法详解
Python两列字符串如何合并?
使用Python时多少有人走过的坑!避险!
总结 Python十大常用文件操作
如何保存Python代码
Python中关于四种字典合并方法的总结
Python中正确的字符串编码规范
安装Python后如何打开
Python如何打印出菱形与三角形以及矩形的代码示例分享
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python 创建空的list,以及append用法讲解