Merge branch 'master' of github.com:TwoWater/Python

pull/59/head
TwoWater 2020-07-28 23:24:15 +08:00
commit 2165e2d019
5 changed files with 13 additions and 17 deletions

View File

@ -1,4 +1,4 @@
# 三、lsit 生成式(列表生成式) #
# 三、list 生成式(列表生成式) #
## 1、创建 list 的方式 ##
@ -48,7 +48,7 @@ print('\n'.join([' '.join ('%dx%d=%2d' % (x,y,x*y) for x in range(1,y+1)) for y
## 2、list 生成式的创建 ##
首先lsit 生成式的语法为:
首先list 生成式的语法为:
```python
[expr for iter_var in iterable]
@ -65,8 +65,8 @@ print('\n'.join([' '.join ('%dx%d=%2d' % (x,y,x*y) for x in range(1,y+1)) for y
```python
# -*- coding: UTF-8 -*-
lsit1=[x * x for x in range(1, 11)]
print(lsit1)
list1=[x * x for x in range(1, 11)]
print(list1)
```
输出的结果:
@ -79,8 +79,8 @@ print(lsit1)
```python
# -*- coding: UTF-8 -*-
lsit1= [x * x for x in range(1, 11) if x % 2 == 0]
print(lsit1)
list1= [x * x for x in range(1, 11) if x % 2 == 0]
print(list1)
```
输出的结果:
@ -95,8 +95,8 @@ print(lsit1)
```python
# -*- coding: UTF-8 -*-
lsit1= [(x+1,y+1) for x in range(3) for y in range(5)]
print(lsit1)
list1= [(x+1,y+1) for x in range(3) for y in range(5)]
print(list1)
```
输出的结果:

View File

@ -16,7 +16,7 @@ Python 就是一门面向对象的语言,
如果你学过 Java ,就知道 Java 的编程思想就是万事万物皆对象。Python 也不例外,在解决实际问题的过程中,可以把构成问题事务分解成各个对象。
面向对象都有两个基本的概,分别是类和对象。
面向对象都有两个基本的概,分别是类和对象。
* **类**

View File

@ -29,12 +29,12 @@ class 就是类method 就是方法。
因此类方法,想要调用类属性,需要以下步骤:
* 在方法上面,用 `@classmethon` 声明该方法是类方法。只有声明了是类方法,才能使用类属性
* 在方法上面,用 `@classmethod` 声明该方法是类方法。只有声明了是类方法,才能使用类属性
* 类方法想要使用类属性,在第一个参数中,需要写上 `cls` , cls 是 class 的缩写,其实意思就是把这个类作为参数,传给自己,这样就可以使用类属性了。
* 类属性的使用方式就是 `cls.变量名`
记住喔,无论是 `@classmethon` 还是 `cls` ,都是不能省去的。
记住喔,无论是 `@classmethod` 还是 `cls` ,都是不能省去的。
省了都会报错。

View File

@ -54,10 +54,6 @@ def main():
* 可以使用多个空行分隔多组相关的函数
* 函数中可以使用空行分隔出逻辑相关的代码
### 2.5、编码
* 文件使用 UTF-8 编码
* 文件头部加入`#-*-conding:utf-8-*-`标识
## 3、import 语句
@ -258,4 +254,4 @@ Optional plotz says to frobnicate the bizbaz first.
"""
"""Oneline docstring"""
```
```

View File

@ -73,7 +73,7 @@ IT 行业相对于一般传统行业,发展更新速度更快,一旦停止
* [迭代器和生成器](/Article/PythonBasis/python7/Preface.md)
- [迭代](/Article/PythonBasis/python7/1.md)
- [Python 迭代器](/Article/PythonBasis/python7/2.md)
- [lsit 生成式(列表生成式)](/Article/PythonBasis/python7/3.md)
- [list 生成式(列表生成式)](/Article/PythonBasis/python7/3.md)
- [生成器](/Article/PythonBasis/python7/4.md)
- [迭代器和生成器综合例子](/Article/PythonBasis/python7/5.md)
* [面向对象](/Article/PythonBasis/python8/Preface.md)