Python3 简介
Python 的发展历史、语言特点、典型应用领域与版本演进。
Python 发展历史
Python was designed by Guido van Rossum around Christmas 1989 and released as 0.9.0 in 1991. The name honours the comedy troupe Monty Python, not the snake.
- 1991 — Python 0.9.0, first public release
- 2000 — Python 2.0, list comprehensions and garbage collection
- 2008 — Python 3.0, deliberate breaking changes
- 2020 — Python 2.7 end of life; Python 3 only
Python 特点
Python's first design goal is readability: indentation marks blocks and the syntax reads like English. Being interpreted it runs right after an edit; dynamic typing keeps code short at the cost of relying more on tests and type hints.
- Easy to learn — clean, consistent syntax
- Interpreted — no build step, fast iteration
- Dynamically typed — no declarations
- Batteries included — broad standard library
- Extensible — interoperates with C/C++
- Cross-platform — same code everywhere
Python 应用
The ecosystem spans nearly every direction; these are the most common landing zones and their stacks.
| Domain | Typical stack |
|---|---|
| Web backend | Django / Flask / FastAPI |
| Data analysis | NumPy / pandas / matplotlib |
| Machine learning | scikit-learn / PyTorch |
| Automation | Ansible / subprocess |
| Scraping | requests / BeautifulSoup |
| Testing | pytest / Selenium |
Python 版本进度
Python 3 ships one minor release per year (3.10, 3.11, 3.12 …), each supported for about five years. Start new projects on the current stable release; verify dependency support before upgrading old ones.
import sys
v = sys.version_info
print("major:", v.major)
print("is python 3:", v.major == 3)
print("supports match:", v >= (3, 10))
print("supports walrus:", v >= (3, 8))major: 3
is python 3: True
supports match: True
supports walrus: TruePython 发展历史
Python 由 Guido van Rossum 于 1989 年圣诞节前后开始设计,1991 年发布 0.9.0。名字取自喜剧团体「Monty Python」,与蟒蛇无关。
- 1991 年 —— Python 0.9.0,首个公开版本
- 2000 年 —— Python 2.0,列表推导式与垃圾回收
- 2008 年 —— Python 3.0,以不兼容方式重构
- 2020 年 —— Python 2.7 停止维护,只保留 Python 3
Python 特点
Python 的第一设计目标是可读性:用缩进表达代码块,语法接近自然语言。它是解释型语言,改完直接跑;动态类型让代码短,代价是更依赖测试与类型注解。
- 易学 —— 语法干净一致
- 解释执行 —— 无需构建,迭代快
- 动态类型 —— 变量无需声明
- 自带电池 —— 标准库覆盖广
- 可扩展 —— 与 C/C++ 互操作
- 跨平台 —— 同一份代码到处跑
Python 应用
生态几乎覆盖所有技术方向,下面是最常见的几类落地场景与对应技术栈。
| 领域 | 常用技术栈 |
|---|---|
| Web 后端 | Django / Flask / FastAPI |
| 数据分析 | NumPy / pandas / matplotlib |
| 机器学习 | scikit-learn / PyTorch |
| 自动化运维 | Ansible / subprocess |
| 网络爬虫 | requests / BeautifulSoup |
| 自动化测试 | pytest / Selenium |
Python 版本进度
Python 3 每年发布一个小版本(3.10、3.11、3.12…),每个版本约支持五年。新项目直接用当前稳定版,老项目升级前先确认依赖是否适配。
import sys
v = sys.version_info
print("major:", v.major)
print("is python 3:", v.major == 3)
print("supports match:", v >= (3, 10))
print("supports walrus:", v >= (3, 8))major: 3
is python 3: True
supports match: True
supports walrus: True