python 列表list初始化
来源:互联网 发布:matlab初始化数组 编辑:程序博客网 时间:2024/05/29 17:25
python 列表list初始化
基本方法
$ pythonPython 3.5.2 (default, Sep 14 2017, 22:51:06) [GCC 5.4.0 20160609] on linuxType "help", "copyright", "credits" or "license" for more information.>>> n = [1, 2, 3, 4]>>> print (n)[1, 2, 3, 4]>>>
连续数字初始化
>>> list1 = [n for n in range(1,6)]>>> print list1 File "<stdin>", line 1 print list1 #python3 特性输出要() ^SyntaxError: Missing parentheses in call to 'print'>>> print (list1)[1, 2, 3, 4, 5]>>>
相同的值初始化
>>> #第一种方法>>> list2 = ['a' for n in range(4)]>>> print(list2)['a', 'a', 'a', 'a']>>> #第二种方法:字符和数字>>> list3 = ['b'] * 4>>> print(list3)['b', 'b', 'b', 'b']>>> list4 = [3] * 4>>> print (list4)[3, 3, 3, 3]>>>
二位数组初始化
$ pythonPython 3.5.2 (default, Sep 14 2017, 22:51:06) [GCC 5.4.0 20160609] on linuxType "help", "copyright", "credits" or "license" for more information.>>> #初始一个5×4的数组>>> multilist = [[1 for col in range(5)] for row in range(4)]>>> print (multilist)[[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]>>>
list 练习
阅读全文
0 0
- python 列表list初始化
- [python] 初始化list of list
- Python 列表(list)操作
- Python 列表(list)操作
- Python 列表(list)操作
- python之list列表
- python学习-列表(list)
- Python 列表(list)操作
- Python list 数据类型:列表
- python list列表操作
- Python 列表(list)操作
- Python 列表(list)操作
- python中的list列表
- Python 列表(list)操作
- Python List列表操作
- python之列表(list)
- Python列表list
- python之列表list
- 数据显示列表 Table中 td 某列字段缩短省略
- In Android 8.0, the MountService class was renamed to StorageManagerService.
- MySQL运算符的优先级
- 跳马
- Hadoop 任务执行方面的优化
- python 列表list初始化
- trainning 2017-11-21
- extern与头文件(*.h)的区别和联系
- IntelliJ IDEA 常用快捷键
- ajax4jsf学习笔记之组件列表
- python libsvm模块在mac上的安装
- 关于某ios app登录关键字加密分析
- mybatis和hibernate的区别的简单的说的一下
- JavaWeb学习篇之----容器Response详解(有关response setCharacterEncoding和setContentType)详细对比说明