On Linux/Unix systems, the default python version is generally 2.x, we can install python3.x in the /usr/local/python3 directory.
After the installation is complete, we can add the path /usr/local/python3/bin to the environment variables of your Linux/Unix operating system, so that you can enter the following command through the shell terminal to start Python3.
$ PATH=$PATH:/usr/local/python3/bin/python3 # Set environment variables
$ python3 --version
Under Window system, you can use the following commands to set Python environment variables, assuming that your Python is installed under C:\Python37:
We can enter the "Python" command in the command prompt to start the Python interpreter:
After executing the above command, the following window message appears:
Python 3.7.9 (default, Apr 31 2020, 17:10:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
Enter the following statement at the python prompt, and then press Enter to see the running effect:
print ("Hello, Python!");
The execution result of the above command is as follows:
When typing a multi-line structure, line continuation is necessary. We can look at the following if statement:
>>> flag = True
>>> if flag:
... print("The flag condition is True!")
The flag condition is True!
Copy the following code to the hello.py file:
Execute the script with the following command:
The output is:
In Linux/Unix systems, you can add the following command at the top of the script to make Python scripts executable directly like SHELL scripts:
#! /usr/bin/env python3
Then modify the script permissions to have execute permissions, the command is as follows:
$ chmod +x hello.py
Execute the following commands:
The output is: