Python Knowledge points Summary One

Source: Internet
Author: User

#-*-coding:utf-8–*-
The purpose is to tell the Python interpreter to read the source code with UTF-8 encoding. Then save with notepad++ as ... and select UTF-8 format to save.
Print U ' Chinese ' (no spaces between U and Chinese)
Print prints each string sequentially, encounters a comma "," and outputs a space, so the output string is spelled like this: the Python string \To escape.

However r‘...‘ , the notation cannot represent multiple lines of string, nor can it represent " a string containing and (why?). )

If a string contains many characters that need to be escaped, it can be cumbersome to escape each character. To avoid this, we can prefix the string to r indicate that it is a raw string, and that the characters inside it do not need to be escaped. For example, if you want to represent multiple lines of string, you can use the ‘‘‘...‘‘‘ expression:

Because Python regards 0 , 空字符串‘‘ and as None False, other values and non-empty strings are considered True,

When calculating a and b , if A is false, the whole result must be false, according to the algorithm, and therefore return a; If A is True, the entire result must depend on B and therefore return B.

In the calculation a or b , if A is true, the whole result must be true, according to the or algorithm, and therefore return a; If A is False, the whole result must depend on B, and therefore return B

The first option is to append the append() new classmate to the end of the list by using the list method:

The method is to use the list insert() method, which accepts two parameters, the first parameter is the index number (the replacement index number), and the second parameter is the new element to be added:

The pop () method always deletes the last element of the list, and it returns the element, so we print out ' Paul ' after we execute L.pop ().

To kick Paul out of the list, we have to locate Paul's position first. Since Paul's index is 2, use Paul to erase it pop(2) :

It is precisely because the tuple with the () definition of a single element is ambiguous, so Python specifies that the element tuple should have a comma ",", which avoids ambiguity:

, tuple's so-called "invariant" is that each element of a tuple, pointing to never change. That point ' a ', it cannot be changed to point to ' B ', pointing to a list, cannot be changed to point to other objects, but the list itself is variable!

The python for loop can then iterate over each element of the list or tuple in turn:

L = [' Adam ', ' Lisa ', ' Bart ']for name in L:    print Name

Python Knowledge points Summary One

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.