# 指定文件编码
-「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)
相关文章
「Python」- 代码片段
「Python」- 安装(CentOS)
「pip」- 模块安装程序
「Python」- 同时运行多个不同版本:虚拟环境(学习笔记)
「Python」- 字符串操作(学习笔记)
本文介绍了Python源代码中指定utf-8编码的方式,详细阐述了`# -*- coding: utf-8 -*-`的用法。同时,讲解了Python中的`yield`关键字,用于创建生成器实现迭代。此外,展示了如何在运行Python脚本后进入交互模式,通过`code.interact(local=locals())`实现。最后,讨论了Python中集合操作的基本用法,包括并集、差集和交集的实现。
184





