Python3基础 list 推导式 生成100以内的偶数列表
- Python : 3.7.0
- OS : Ubuntu 18.04.1 LTS
- IDE : PyCharm 2018.2.4
- Conda : 4.5.11
- typesetting : Markdown
code
coder@Ubuntu:~$ source activate py37
(py37) coder@Ubuntu:~$ ipython
Python 3.7.0 (default, Jun 28 2018, 13:15:42)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: test = [each for each in range(100) if not (each % 2 == 1)]
In [2]: test
Out[2]:
[0,
2,
4,
6,
8,
10,
12,
14,
16,
18,
20,
22,
24,
26,
28,
30,
32,
34,
36,
38,
40,
42,
44,
46,
48,
50,
52,
54,
56,
58,
60,
62,
64,
66,
68,
70,
72,
74,
76,
78,
80,
82,
84,
86,
88,
90,
92,
94,
96,
98]
In [3]: exit
(py37) coder@Ubuntu:~$ source deactivate
coder@Ubuntu:~$
resource
- [文档] docs.python.org/3
- [规范] www.python.org/dev/peps/pep-0008
- [规范] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules
- [源码] www.python.org/downloads/source
- [ PEP ] www.python.org/dev/peps
- [平台] www.cnblogs.com
- [平台] gitee.com
Python具有开源、跨平台、解释型、交互式等特性,值得学习。
Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。
代码的书写要遵守规范,这样有助于沟通和理解。
每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。
Python3基础 list 推导式 生成100以内的偶数列表的更多相关文章
- Python3基础 dict 推导式 生成10以内+奇数的值为True 偶数为False的字典
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 list 推导式 生成与已知列表等长度+元素为0的列表
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python小代码_6_列表推导式求 100 以内的所有素数
import math a = [p for p in range(2, 100) if 0 not in [p % d for d in range(2, int(math.sqrt(p)) + 1 ...
- Python3基础 生成器推导式 简单示例
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- python3进阶之推导式之列表(list)推导式(comprehensions)
1.前言 推导式,英文名字叫comprehensions,注意与comprehension(理解)只有s字母之差.推导式又可以叫解析式,推导式可以从一种数据序列构建新的数据序列的结构体.推导式分为,列 ...
- Python3基础数据类型(数字、字符串、元组、列表、集合、字典)
笔记参考了菜鸟教程 Python 中的变量不需要声明,赋值才创建.赋值给变量的是什么类型变量就是什么类型 多个变量赋值 1 a, b, c = 1, 2, "runoob" 标准数 ...
- for计算100以内的偶数和
#include "stdio.h" void main() { ,sum=; ;d++) { ==) { sum=sum+d; } }printf("100以内所有偶数 ...
- python练习笔记——用列表推导式生成二维列表
用列表推导式如何生成如下列表:[[1, 2, 3], [4, 5, 6], [7, 8, 9]] inner_list = [] outer_list = [] for i in range(1,10 ...
- python 基础(六) 推导式
列表推导式 概念:提供了一种创建列表的简单快速的途径 (1) 一般形式 myList = [x for x in range(10)] #分解后 myList = [] for x in rang ...
随机推荐
- 2018/04/03 PHP 中的 进制计算问题
还是先抛出一个问题 017 + 1 = ? -- 如果你知道的话,那也就不用看下面了,哈哈. 答案是 // 15 -- 如果你想的答案和这个不对的话,说明你也有这个问题,也应该学习一下啦. -- 首先 ...
- 设置elasticsearch一次最大数量查询
PUT my_index/_settings?preserve_existing=true{ "max_result_window": "2000000000" ...
- grunt学习一
grunt是前端自动化工具之一.下面是是grunt的简单小示例: 在使用grunt,确保安装nodejs,如果不清楚,可以百度找相关教程,这个教程已经烂大街了. 1.打开cmd,以管理员的身份.(或者 ...
- 3.cassandra遇到内存占用过高的问题
目前cssandra的内存分配如下: https://docs.datastax.com/en/cassandra/2.1/cassandra/operations/ops_tune_jvm_c.ht ...
- 安装HDF5及在VS下配置HDF5
最近要用到HDF5来存储数据,想要安装尝试用一下.发现网上有两种安装方式,一种是obtain518.html:获取最新的HDF5-1.8软件;另一种是cmakebuild518.html:使用CMAK ...
- 高性能mysql第6章
第6章,优化配置 https://www.cnblogs.com/musings/p/5913157.html 1:服务器读取的配置文件,可以使用下面的命令查询 admin@iZwz92c0zpe8t ...
- ppt插入声音
1:点击插入>音频>文件中的音频 2:插入成功后,会出现一个声音的图表 3:对播放格式进行设置,设置循环播放等. 4:双击对声音进行编辑 ,会出现右边的各个组件, 5:点击下拉框>效 ...
- 使用浏览器,调试js代码
1:创建html网页和js文件 <!doctype html> <html> <head> <meta charset="utf-8"&g ...
- [LeetCode] 42. Trapping Rain Water_hard tag: Two Pointers
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- iOS 开发笔记-plist使用
1.创建一个plist 2.填写为ImageList.plist 3.填入数据 4.完成 加载代码: @interface UYViewController () //图片信息的数组 @propert ...