“Python3 教程”的版本间差异

本页内容
下一节: Python3_简介
Neo讨论 | 贡献
 
(未显示同一用户的4个中间版本)
第10行: 第10行:
我们可以在命令窗口(Windows 使用 win+R 调出 cmd 运行框)使用以下命令查看我们使用的 Python 版本:
我们可以在命令窗口(Windows 使用 win+R 调出 cmd 运行框)使用以下命令查看我们使用的 Python 版本:


<sample title="" desc="" lang="python" hererun="1">
<sample title="" desc="" lang="shell" hererun="1">
python -V
python3 -V
#python3 --version
python --version
  </sample>
  </sample>
以上命令执行结果如下:
以上命令执行结果如下:


<sample title="" desc="" lang="python" hererun="1">
<sample title="" >
Python 3.3.2
Python 3.3.2
  </sample>
  </sample>
你也可以进入Python的交互式编程模式,查看版本:
你也可以进入Python的交互式编程模式,查看版本:


<sample title="" desc="" lang="python" hererun="1">
<sample title="" desc="" lang="python">
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
Type "copyright", "credits" or "license()" for more information.
第43行: 第42行:
你可以将以上代码保存在 '''hello.py''' 文件中并使用 python 命令执行该脚本文件。
你可以将以上代码保存在 '''hello.py''' 文件中并使用 python 命令执行该脚本文件。


<sample title="" desc="" lang="python" hererun="1">
<sample title="" >
$ python3 hello.py
$ python3 hello.py
  </sample>
  </sample>
以上命令输出结果为:
以上命令输出结果为:


<sample title="" desc="" lang="python" hererun="1">
<sample title="" >
Hello, World!
Hello, World!
  </sample>
  </sample>

2022年8月22日 (一) 21:31的最新版本

Python 3 教程

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

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

查看 Python 版本

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


示例

python3 -V
#或 python3 --version

以上命令执行结果如下:


示例

Python 3.3.2

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


示例

Python 3.3.2 (v3.3.2: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!"

hello.py 文件代码:

示例

#!/usr/bin/python3

print("Hello, World!")

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

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


示例

$ python3 hello.py

以上命令输出结果为:


示例

Hello, World!
下一节: Python3_简介
此页面最后编辑于2022年8月22日 (星期一) 21:31。