20 Basics of Python programming

Source: Internet
Author: User

Other common methods of strings:

Ord (char) # returns the code value corresponding to the char character, which can be a Chinese character

Chr (x) # Enter a Unicode code to return the corresponding character

eval (str) # returns the contents of Str in the form of code

REPR (x) returns the object's str format, suitable for machine execution

String formatting

% formatting:

%[flags][width][.precision]typecode

Format formatted:

[Fill] [Align] [Sign] [#] [Width] [. Precision] [Type]

Fill: Filling symbol

Align: alignment < Align Left,> right, ^ center align

Sign: Display symbol, + display plus sign,-display symbol

#: 0b,0o,0x is displayed for 2,4,8

Width: Wide

, thousands of bits

. Precision: Accuracy

Type:s string D shaping f floating-point type

Bytes:

Create bytes:

B1 = B ' Hello ' # Add a B before the string

B2 = Byte ("Chinese", ' utf-8 ')

To set the encoding format:

#-*-Coding:utf-8-*-

Import Sys

Sys.setdefaultencoding (' Utf-8 ') #修改系统默认编码格式

String to byte: ' Chinese '. Endcode (' Utf-8 ')

byte-to-string: B ' \xe4\xb8\xad\xe6\x96\x87 '. Decode (' Utf-8 ')

20 Basics of Python programming

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.