Python Learning Notes

Source: Internet
Author: User

For example, \ n indicates a newline, \ t represents a tab
R ' means the string inside ' is not escaped by default
Boolean value: Indicates that the input code is correct or false (true, and vice versa). Boolean values can be operated with and, or, and not.

And for and operations: positive positive, negative minus
Or operation: one is correct
The null value is a special value in Python, denoted by none. None cannot be understood as 0, because 0 is meaningful, and none is a special null value.
Variable:
The variable can be an integer (a=1), a string (t_007 = ' T007 '), a Boolean value (Answer=ture)
In Python, equals = is an assignment statement that can assign any data type to a variable, the same variable can be repeatedly assigned, and can be a variable of different types
A language that is not fixed by itself is called a dynamic language, and it corresponds to a static language. Static languages must specify the variable type when defining the variable, and if the type does not match, the error will be
Constants are usually represented with all uppercase variable names
In Python, there are two kinds of division, one division is/: There is also a division is//, called a floor divide, two integers of division is still an integer: (leave the remainder, because//division only takes the integer part of the result)
For the encoding of a single character, Python provides an integer representation of the Ord () function to get the character, and the Chr () function converts the encoding to the corresponding character
If you want to transfer on the network, or save to disk, you need to turn str into bytes in bytes.

Python uses single or double quotation marks with a B prefix for data of type bytes: The plain English str can be encoded in ASCII as bytes, the content is the same, and STR with Chinese can be encoded with UTF-8 as bytes. STR, which contains Chinese, cannot be ASCII encoded because the range of Chinese encodings exceeds the ASCII encoding range and Python will error.
If you want to transfer on the network, or save to disk, you need to turn str into bytes in bytes.

Python uses single or double quotation marks with a B prefix for data of type bytes:
To calculate how many characters a str contains, you can use the Len () function:
1 Chinese characters are UTF-8 encoded and typically consume 3 bytes, while 1 English characters take up only 1 bytes
To avoid garbled problems, you should always use UTF-8 encoding to convert str and bytes.
#!/usr/bin/env Python3
#-*-Coding:utf-8-*-(note for UTF8 format)
>>> ' Hi,%s, you have $%d. '% (' Michael ', 1000000)
' Hi, Michael, you have $1000000. '

Python Learning Notes

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.