Python learning notes for head files

The first is to set up the running mode of Python.

That is, our common line, /usr/bin/python3, or /usr/bin/python!

Mainly used to specify the mode of operation.

Python3 xxx.py or Python xxx.py is equivalent to our input in the terminal.

Specifying this line allows us to turn it into an executable program that first gives permission Chmod 777 xxx.py to the terminal

Then you can run the program by double clicking.

 Remember that you have to put it in the first line.

#coding:utf-8
#!/usr/bin/python

while True:
    print('yes')

Can’t run in second rows.

#!/usr/bin/python
#coding:utf-8

while True:
    print('yes')

Put in the first row and run.

The second is if it is directly executed at the terminal.

For example, if the terminal is Python xxx.py and the running mode in this file is Python 3, then the terminal will have priority over the first line if specified many times in the file

 

Then the encoding format.

Usually it will be set to UTF-8 or utf8 (equivalent), but there are two styles.

The first:

# coding=utf-8

Second kinds (mainstream)

# -*- coding: utf-8 -*

 

Leave a Reply

Your email address will not be published. Required fields are marked *