Python 3 Tutorial
Version 3.0 of Python, often called Python 3000 or Py3k for short, is a major upgrade over earlier versions of Python. To avoid carrying too much baggage, Python 3.0 was designed without backward compatibility in mind.
The Python introduction and installation tutorial is already covered inPython 2.X Tutorial, so it will not be repeated here.
You can also clickDifferences between Python2.x and 3.x versionsto see the differences between the two.
This tutorial focuses on learning Python 3.x; if you are using Python 2.x, please go to Python 2.X Tutorial。
Officially announced: on January 1, 2020, updates to Python 2 stopped.
Check the Python version
We can check the Python version we are using in a command window (on Windows use win+R to bring up the cmd run box) with the following command:
python -V
或
python --version
The result of the above command is as follows:
Python 3.3.2
You can also enter Python's interactive programming mode to check the version:
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.
>>>
The first Python3.x program
For most programming languages, the first introductory code is "Hello World!", and the following code uses Python to output "Hello World!":
hello.py file code:
#!/usr/bin/python3
(
"Hello, World!"
)
Run Example »
The common file extension for Python is .py.
You can save the above code in a hello.py file and run the script using the python command.
$ python3 hello.py
The output of the above command is:
Hello, World!