查看 Python 版本
Python 官网
Python 的 3.0 版本,常被称为 Python 3000,或简称 Py3k。相对于 Python 的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0 在设计的时候没有考虑向下兼容。
如何查看 Python 版本
我们可以在命令窗口(Windows 使用 win+R 调出 cmd 运行框)使用以下命令查看我们使用的 Python 版本:
python -V
或
python --version
以上命令执行结果如下:
Python 3.8.0
在命令提示符/终端中输入python并回车可以进入 Python 的交互式编程模式,在这里也可以查看版本:
Python 3.8.0 (tags/v3.8.0:b0, May 20 2020, 15:00:54) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "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 命令执行该脚本文件。
python hello.py
以上命令输出结果为:
Hello, World!
官网循环Demo:
# For loop on a list
numbers = [2, 4, 6, 8]
product = 1
for number in numbers:
product = product * number
print('The product is:', product)
The product is: 384