01 Hello World!

The first run a Python program

For most programming languages, first introductory programming code is "Hello World!", Use the following code to Python output "Hello World!":

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

Precautions

# Script on the first line! / Usr / bin / python explanation, I believe that many students are not familiar with Linux system needs to popularize this knowledge, the first line of the script language, only to Linux / Unix users apply this script to specify to perform what the interpreter. There's sentence, after adding execute permissions, you can directly use ./ execution, or be wrong, because no python interpreter.

! / Usr / bin / python is time to tell the operating system to execute the script, call the python interpreter in the / usr / bin.

! / Usr / bin / env python This usage is intended to prevent the operating system the user will not have python installed in the default / usr / bin path inside.

When the system sees this line, the first thing will be to find the installation path settings in the env python, and then calls the interpreter program under the corresponding path to complete the operation.

! / Usr / bin / python equivalent to write dead python path.

! / Usr / bin / env python would go looking for python directory environment settings, you can enhance the portability of code, we recommended such an approach.

Divided into two situations:

  • 1 If you call the python script, use:
    python script.py

    ! / Usr / bin / python is ignored, equivalent to comment

  • 2:00 If you call python script, use:
    ./script.py

    ! / Usr / bin / python interpreter specified path

Guess you like

Origin www.cnblogs.com/stephenmc/p/12003147.html