Skip to content

Commit

Permalink
更新了部分文档和图片资源
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfrued committed Apr 26, 2020
1 parent 05998c8 commit a9ded25
Show file tree
Hide file tree
Showing 29 changed files with 61 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Day16-20/16-20.Python语言进阶.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@


@singleton
class President():
class President:
"""总统(单例类)"""
pass
```
Expand Down
Binary file removed res/pycharm-activate.png
Binary file not shown.
Binary file added res/pycharm-activation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed res/pycharm-comm-django-1.png
Binary file not shown.
Binary file removed res/pycharm-comm-django-2.png
Binary file not shown.
Binary file removed res/pycharm-comm-django-3.png
Binary file not shown.
Binary file removed res/pycharm-comm-django-4.png
Binary file not shown.
Binary file removed res/pycharm-comm-django-5.png
Binary file not shown.
Binary file removed res/pycharm-comm-django-6.png
Binary file not shown.
Binary file removed res/pycharm-comm-django-7.png
Binary file not shown.
Binary file removed res/pycharm-comm-django-8.png
Binary file not shown.
Binary file removed res/pycharm-create-launcher-script.png
Binary file not shown.
Binary file added res/pycharm-create-launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/pycharm-import-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/pycharm-install-plugins.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/pycharm-installation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed res/pycharm-new-project.png
Binary file not shown.
Binary file removed res/pycharm-plugins.png
Binary file not shown.
Binary file removed res/pycharm-prof-django-2.png
Binary file not shown.
Binary file removed res/pycharm-prof-django-3.png
Binary file not shown.
Binary file added res/pycharm-project-wizard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/pycharm-run-result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed res/pycharm-set-ui-theme.png
Binary file not shown.
Binary file added res/pycharm-ui-themes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/pycharm-welcome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/pycharm-workspace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 56 additions & 46 deletions 玩转PyCharm.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 番外篇/租房网项目接口文档.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

最后修改时间:

接口说明:登录成功后,会在`tb_user_token`表中保存或更新用户令牌(token)。
接口说明:登录成功后,会生成或更新用户令牌(token)。

使用帮助:测试数据库中预设了四个可供使用的账号,如下表所示。

Expand Down
6 changes: 3 additions & 3 deletions 番外篇/那些年我们踩过的那些坑.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- `is`比较的是两个整数对象的id值是否相等,也就是比较两个引用是否代表了内存中同一个地址。
- `==`比较的是两个整数对象的内容是否相等,使用`==`时其实是调用了对象的`__eq__()`方法。

知道了`is``==`的区别之后,我们可以来看看下面的代码,了解Python中整数比较有哪些坑
知道了`is``==`的区别之后,我们可以来看看下面的代码,了解Python中整数比较有哪些坑**以CPython解释器为例**,大家先看看下面的代码。

```Python
def main():
Expand Down Expand Up @@ -36,7 +36,7 @@ if __name__ == '__main__':
main()
```

上面代码的部分运行结果如下图所示,出现这个结果的原因是Python出于对性能的考虑所做的一项优化。对于整数对象,Python把一些频繁使用的整数对象缓存起来,保存到一个叫`small_ints`的链表中,在Python的整个生命周期内,任何需要引用这些整数对象的地方,都不再重新创建新的对象,而是直接引用缓存中的对象。Python把频繁使用的整数对象的值定在[-5, 256]这个区间,如果需要这个范围的整数,就直接从`small_ints`中获取引用而不是临时创建新的对象。因为大于256或小于-5的整数不在该范围之内,所以就算两个整数的值是一样,但它们是不同的对象
上面代码的部分运行结果如下图所示。这个结果是因为CPython出于性能优化的考虑,把频繁使用的整数对象用一个叫`small_ints`的对象池缓存起来造成的。`small_ints`缓存的整数值被设定为`[-5, 256]`这个区间,也就是说,如果使用CPython解释器,在任何引用这些整数的地方,都不需要重新创建`int`对象,而是直接引用缓存池中的对象。如果整数不在该范围内,那么即便两个整数的值相同,它们也是不同的对象

![](./res/int-is-comparation.png)

Expand All @@ -58,7 +58,7 @@ if __name__ == "__main__":
main()
```

程序的执行结果已经用注释写在代码上了。够坑吧!看上去`a`、`b`和`c`的值都是一样的,但是`is`运算的结果却不一样。为什么会出现这样的结果,首先我们来说说Python程序中的代码块。所谓代码块是程序的一个最小的基本执行单位,一个模块文件、一个函数体、一个类、交互式命令中的单行代码都叫做一个代码块。上面的代码由两个代码块构成,`a = 257`是一个代码块,`main`函数是另外一个代码块。Python内部为了进一步提高性能,凡是在一个代码块中创建的整数对象,如果值不在`small_ints`缓存范围之内,但在同一个代码块中已经存在一个值与其相同的整数对象了,那么就直接引用该对象,否则创建一个新的对象出来,这条规则对不在`small_ints`范围的负数并不适用,对负数值浮点数也不适用,但对非负浮点数和字符串都是适用的,这一点读者可以自行证明。所以 `b is c`返回了`True`,而`a`和`b`不在同一个代码块中,虽然值都是257,但却是两个不同的对象,`is`运算的结果自然是`False`了。
程序的执行结果已经用注释写在代码上了。够坑吧!看上去`a`、`b`和`c`的值都是一样的,但是`is`运算的结果却不一样。为什么会出现这样的结果,首先我们来说说Python程序中的代码块。所谓代码块是程序的一个最小的基本执行单位,一个模块文件、一个函数体、一个类、交互式命令中的单行代码都叫做一个代码块。上面的代码由两个代码块构成,`a = 257`是一个代码块,`main`函数是另外一个代码块。CPython内部为了进一步提高性能,凡是在一个代码块中创建的整数对象,如果值不在`small_ints`缓存范围之内,但在同一个代码块中已经存在一个值与其相同的整数对象了,那么就直接引用该对象,否则创建一个新的对象出来,在早些时候的CPython中,这条规则对负数并不适用,但对非负整数、浮点数和字符串都是适用的,这一点读者可以自行证明。所以 `b is c`返回了`True`,而`a`和`b`不在同一个代码块中,虽然值都是257,但却是两个不同的对象,`is`运算的结果自然是`False`了。
为了验证刚刚的结论,我们可以借用`dis`模块(听名字就知道是进行反汇编的模块)从字节码的角度来看看这段代码。如果不理解什么是字节码,可以先看看[《谈谈 Python 程序的运行原理》]((http://www.cnblogs.com/restran/p/4903056.html))这篇文章。可以先用`import dis`导入`dis`模块并按照如下所示的方式修改代码。

```Python
Expand Down

0 comments on commit a9ded25

Please sign in to comment.