Python 基础教程

Python 是一种解释型、面向对象、动态数据类型的高级程序设计语言。

Python 由 Guido van Rossum 于 1989 年底发明,第一个公开发行版发行于 1991 年。

像 Perl 语言一样, Python 源代码同样遵循 GPL(GNU General Public License) 协议。

官方宣布,2020 年 1 月 1 日, 停止 Python 2 的更新。

Python 2.7 被确定为最后一个 Python 2.x 版本。

Python 的 3.0 版本,常被称为 Python 3000,或简称 Py3k。相对于 Python 的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0 在设计的时候没有考虑向下兼容。

查看 Python 版本

我们可以在命令窗口(Windows 使用 win+R 调出 cmd 运行框)使用以下命令查看我们使用的 Python 版本:

复制代码
python -V
或
python --version

以上命令执行结果如下:

复制代码
Python 3.9.10

你也可以进入Python的交互式编程模式,查看版本:

复制代码
Python 3.9.10 (v3.9.10:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 

第一个Python3.x程序

对于大多数程序语言,第一个入门编程代码便是 "Hello World!" ,以下代码为使用 Python 输出 "Hello World!"

复制代码
#!/usr/bin/python3

print("Hello, World!")

Python 常用文件扩展名为 .py。

你可以将以上代码保存在 hello.py 文件中并使用 python 命令执行该脚本文件。

复制代码
$ python3 hello.py

以上命令输出结果为:

复制代码
Hello, World!
相关推荐
AI探索者10 分钟前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者11 分钟前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh2 小时前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅2 小时前
Python函数入门详解(定义+调用+参数)
python
曲幽3 小时前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama
两万五千个小时6 小时前
落地实现 Anthropic Multi-Agent Research System
人工智能·python·架构
哈里谢顿9 小时前
Python 高并发服务限流终极方案:从原理到生产落地(2026 实战指南)
python
用户8356290780511 天前
无需 Office:Python 批量转换 PPT 为图片
后端·python
markfeng81 天前
Python+Django+H5+MySQL项目搭建
python·django
GinoWi1 天前
Chapter 2 - Python中的变量和简单的数据类型
python