「Python」- 杂记 @20210313

# 指定文件编码

-「Working with utf-8 encoding in Python source
-「Correct way to define Python source code encoding
-「PEP 263 -- Defining Python Source Code Encodings
-「2.1.4. Encoding declarations
根据官方文档所述,只要第一行或者第二行匹配正则表达式coding[=:]\s*([-\w.]+)则会被视为编码声明。

所以对于# -*- coding: utf-8 -*-coding: utf-8才是关键部分。

# yield

-「python中yield的用法详解——最简单,最清晰的解释

# 运行脚本后进入交互模式

-「Enter Interactive Mode In Python

# In Python Script
import code
code.interact(local=locals())

# In Shell
python -i foo.py

# 交集、并集、差集

-「python获得两个数组交集、并集、差集的方法

set_a = set(foo_a)
set_b = set(foo_b)

# 并集
set_a.union(set_b)

# 差集
set_a.difference(set_b) # 仅存与a中的元素

# 交集
set_a.intersection(set_b)

相关文章

「Python」- 安装(CentOS)
「pip」- 模块安装程序
「Python」- 同时运行多个不同版本:虚拟环境(学习笔记)
「Python」- 字符串操作(学习笔记)
「Python」- 代码片段

posted @ 2021-03-13 16:35  研究林纳斯写的  阅读(49)  评论(0编辑  收藏  举报