May 10, 2021 Python3
On Linux/Unix systems, Python interpreters are usually installed in valid paths (directories) such as /usr/local/python3.
We can add the path /usr/local/python3/bin to the environment variables of your Linux/Unix operating system (preferably with reference to your Python installation path) so that you can start Python by entering the following command at the shell terminal.
$ PATH=$PATH:/user/local/python3/bin/python #设置环境变量
$ python3 --vesion
Python 3.7.6
Under the Window system, you can set Python's environment variables with the following commands, assuming that your Python is installed under C:
set path=%path%;C:\python37
When IDLE is turned on, the default is interactive programming, similar to a cmd window.
We can start the Python interpreter by entering the "Python" command in the command prompt:
$ python3
After executing the above command, the following window message appears:
$ python3
Python 3.4。0 (default, Mar 16 2014, 09:25:04)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Enter the following statement in the Python prompt, and then press enter to see how it works:
print ("Welcome to W3Cschool!");
The above commands are executed as follows:
When you type a multi-line structure, a continued line is a must. Let's look at the following if statement:
>>> the_world_is_flat = True
>>> if the_world_is_flat:
... print("Be careful not to fall off!")
...
Be careful not to fall off!
Click file → new script file, under which scripting is carried out.
Copy the following code to W3C.py file:
print ("Welcome to W3Cschool!");
The script is executed with the following command:
python W3C.py
The output is:
Welcome to W3Cschool!
In a Linux/Unix system, you can add the following commands at the top of the script so that the Python script can execute as directly as the SHELL script:
#! /usr/bin/env python3.7
Then modify the script permissions so that they have execution permissions, and the command is as follows:
$ chmod +x W3C.py
Follow these commands:
./hello.py
The output is:
Welcome to W3Cschool!