Python Learning Notes _ character encoding

Source: Internet
Author: User

1. Character encoding

ASCII code: One byte=8 bit, 128 characters in English letter case, Roman character, etc.

GB2312, GBK, GB18030 (China's own) Express Chinese characters, get up early general mobile device support to GB2312

Unicode: Universal code, 2 byte=16 bits representing all characters

UTF-8: A dynamically varying length encoding. Save in English 1byte, Chinese 3byte. Python3 character Set bit UTF-8. Python2 default encoding is ASCII code, if you want to support Chinese characters in Python2, add #-*-coding:utf-8-*-at the top of the code

2. Symbol syntax

A single line in front of the line with #, paragraph comments in a row before the paragraph and after the paragraph with ""

"Can also be used to refer to a paragraph string

Single and double quotes are exactly the same in Python, and special symbols in the referenced content are not escaped. (single quotes are escaped in Bashell)

Referencing a variable in a string, Method 1 uses the + connection

Method 2: Use the placeholder%s to write% after the string (variable name 1, variable name 2) # # #s表示string, D for digital numbers, F for floating-point number floating, percent sign to be the same as variable type, python default Volume types are str, print variable type: print (type (variable name))

Method 3: Use {} After the string to add. Format () For example

Method 4:

Convert variable type int () str ()

Input (' string ') # # #在python27里位raw_input ()

3.getpass Module

Import Getpass

passwd = Getpass.getpass ()

Python Learning Notes _ character encoding

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.