python 1.1 (version, environment variables)

Python 3 Tutorial

python3

Version 3.0 of Python, often referred to as Python 3000, or Py3k for short. This is a big upgrade from earlier versions of Python. In order not to bring too much burden, Python 3.0 was not designed with backward compatibility in mind.

Python introduction and installation tutorial We have already introduced it in the Python 2.X version of the tutorial , so I won't repeat it here.

You can also click  Python 2.x and 3​​.x version differences  to see the difference between the two.

This tutorial is mainly aimed at learning Python 3.x version. If you are using Python 2.x version, please move to the Python 2.X version tutorial .


Check python version

We can use the following command to see which version of Python we are using:

python - V

The result of executing the above command is as follows:

Python3.3.2 

You can also enter Python's interactive programming mode, check the version:

Python3.3.2(v3.3.2:d047928ae3f6,May162013,00:03:43)[MSC v.160032 bit (Intel)] on win32
Type"copyright","credits"or"license()"for more information.>>>             
 

The first Python3.x program

For most programming languages, the first introductory programming code is "Hello World!", the following code prints "Hello World!" in Python:

Example (Python 3.0+)

#!/usr/bin/python3 print("Hello, World!");

Running the instance »

You can save the above code in hello.py file and execute the script file using python command.

$ python3 hello.py

The output of the above command is:

Hello,World! 

----------------------------------------------------------------------------------------------------------------------------------

The first line of comments can be omitted under Windows:

#!/usr/bin/python3

The first line of comment marks the path to python, telling the operating system to call the python interpreter under /usr/bin when executing the script.

In addition, there are the following forms (recommended writing):

#!/usr/bin/env python3

This usage first searches the python installation path in the env (environment variable) setting, and then calls the interpreter program under the corresponding path to complete the operation.

   Feel the world indifferently

  107***5530@qq.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326455259&siteId=291194637