Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1deb3d2

Browse files
authored
Update README.md
1 parent d3e792c commit 1deb3d2

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

‎README.md‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ python最先的格式化字符串方法是%,但他的致命缺点是支持的
134134
<generator object <genexpr> at 0x0000028F8B774200>
135135
>>>
136136
```
137+
通过列表生成式,可以直接创建一个列表。但是,受到内存限制,列表容量肯定是有限的。而且,创建一个包含百万元素的列表,不仅是占用很大的内存空间,如:我们只需要访问前面的几个元素,后面大部分元素所占的空间都是浪费的。因此,没有必要创建完整的列表(节省大量内存空间)。在Python中,我们可以采用生成器:边循环,边计算的机制—>generator
138+
137139
* 666 and True => 666
138140
* ord() 函数是 chr() 函数(对于8位的ASCII字符串)或 unichr() 函数(对于Unicode对象)的配对函数,它以一个字符(长度为1的字符串)作为参数,返回对应的 ASCII 数值,或者 Unicode 数值
139141
* 进制转换
@@ -147,7 +149,30 @@ python最先的格式化字符串方法是%,但他的致命缺点是支持的
147149
* [字符串处理支持多种操作](https://www.runoob.com/python3/python3-string.html)
148150
* round()保留几位小数 返回浮点数x的四舍五入值。
149151
* eval()神奇公式: 用来执行一个字符串表达式,并返回表达式的值。
150-
* OOP
152+
## OOP
153+
### *args and **kwargs
154+
* 当你不确定你的函数里将要传递多少参数时你可以用*args.例如,它可以传递任意数量的参数
155+
```
156+
>>> def print_everything(*args):
157+
for count, thing in enumerate(args):
158+
... print '{0}. {1}'.format(count, thing)
159+
...
160+
>>> print_everything('apple', 'banana', 'cabbage')
161+
0. apple
162+
1. banana
163+
2. cabbage
164+
```
165+
* 相似的,**kwargs允许你使用没有事先定义的参数名:
166+
```
167+
>>> def table_things(**kwargs):
168+
... for name, value in kwargs.items():
169+
... print '{0} = {1}'.format(name, value)
170+
...
171+
>>> table_things(apple = 'fruit', cabbage = 'vegetable')
172+
cabbage = vegetable
173+
apple = fruit
174+
```
175+
未完待续
151176
* 正则表达式
152177
* `re.match(pattern, string, flags=0)` 尝试从字符串的起始位置匹配一个模式,如果不是起始位置匹配成功的话,match()就返回None
153178
* pattern:匹配的正则表达式

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /