Python (3) coding doubts

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.