# 2021-01-04 #「Python」- 杂记
# 指定文件编码
-「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
# 交集、并集、差集
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)