1. Describe two lines in the following code #
The first line of comments is to tell the Linux/os x system that this is a python executable and the Windows system ignores this comment;
The second line of comments is to tell the Python interpreter to read the source code according to the UTF-8 encoding, otherwise the Chinese output you write in the source code may be garbled.
#!/usr/bin/env python#-*-coding:utf-8-*-print u ' Chinese test normal ' print '----------------------------------------------' Print U ' ASCII encoding, a byte ' Print U ' Unicode encoding, usually 2 bytes, java default is this ' Print U ' uf8 is variable length encoded Unicode, according to different 1-6 bytes, English 1 bytes, Chinese characters 3 bytes ' PR int u ' computer's in-memory unification is Unicode, we normally use GBK saved text, loading into memory will gbk-unicode the conversion process ' Print U ' what we see on the screen is converted from memory Unicode to the corresponding encoded ' print ' without U, Garbled ' print '----------------------------------------------' print ' \ n ' #换行print ' ' #换行print ' line1 ' Print "" #换行print ' line2 '
The point is to u, no garbled
When I change the encoding format of the file, the compilation is different. The following is the effect of Unicode
The front 2 posts are used
#-*-coding:cp936-*-
The GBK corresponding code page is CP936, which represents GBK
Microsoft also defined code page:cp54936 for GB18030. By default, we save the file directly as the Gbk,window system default
I do not know that people understand a little. Welcome to the message discussion.
Python (3) coding doubts