Python Learning Essay (detail summary)

Source: Internet
Author: User

1.16 binary with 0x prefix and 0-9,a-f representation eg:0xff00

2. String is ‘‘ "" any text in or enclosed eg: ' abc ', ' XYZ '

3. In Python, the variable name must be a combination of case English, numeric, and underscore (_) and cannot start with a number

4. When defining a string, if the string itself contains both ' and contains ', the

The string contains ', you can use ' "" in Eg:i ' m OK ====> "I ' m OK"

The string contains "Eg:learn", which can be enclosed in "python" everyday. ====> ' Learn "Python" everyday. '

or escape character \ Escaped Eg:bob said "I m OK". ====> ' Bob said \ "I\ ' m ok\". Other escape characters \ n, \ t (tab), \ \ (\ character itself)

5. A string that does not contain "or" preceded by a prefix R, the following string does not need to escape the eg:r ' \ (~_~)/\ (~_~)/'

6. Multiline string, can be used to ‘‘‘...‘‘‘ denote eg: ' line 1\nline 2\nline 3 '

====> ' Line 1

Line 2

Line 3 "'

7. The multiline string is preceded by R, and the multiline string becomes a raw string, and the characters in the string do not need to be escaped.

8. When using a Unicode string, you can add #-*-Coding:utf-8 to the first line-*-

9. Short Circuit Calculation rule:

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, so it returns B.

10.list is an ordered set of elements that can be added and removed at any time.

Format: [ ] A list object that is surrounded by all the elements of the list. When the parameter is-n, the element that the parameter refers to is the nth-second element

Action: append() method to append the new element to the end of the list.

       insert(参数,‘元素‘)method to add the element to the position indicated by the parameter.

       pop(参数)method to delete the element that the parameter refers to, and a null argument to delete the bottom element.

11.tuple becomes a tuple with a sequence table that cannot be modified after it is created. You can use list nesting to a tuple to implement a tuple modification. Eg:t = (' A ', ' B ', [' A ', ' B '])

Format: Use () to enclose all elements of a tuple, which is a tuple object. Cell tuple to add a comma Eg:t = (1,)

12. When using the IF statement, pay attention to the indentation rules: the first line indents 4 spaces, the exit indentation requires more than one line to enter.

13.dict is used to store two parameters with associated relationships, establishing a mapping relationship between key and value, and key is not duplicated.

Format: with {}, according to key and value of the corresponding relationship, write out. The stored key-value sequence pairs are not sequential.

Action: The method of D [key] finds the corresponding value or uses the Get () method. eg print d.get (' a ');

Update Dict eg:d [' A ']=72 using assignment statements

14.set stores only keys that do not store value and store unordered collections compared to Dict. s = set ([' A ', ' B ', ' C '])

Action: The method to create the set is to call set () and pass in a list. Eg:s = Set ([' A ', ' B ', ' C '])

Methods for adding elements Add () Eg:s.add (4)

Methods for deleting elements remove () Eg:s.remove (4)

15. On the interactive command line, see Help for the X function by helping (x)

16. Define a function to use the DEF statement, write down the function name, parentheses, the arguments in parentheses, and the colon: finally return the function value with return. Eg:def my_abs (x):

17. Slice the list, slice format: l[start:end:step]

Enumerate () function, you can bind indexes at the same time in the for loop index and element name Eg:for T in enumerate (L):

19. The value of the Iteration Dict object uses D.values () or itervalues () Eg:for v in D.values (): For V in D.itervalues ()://values () method converts dict to A list, and the Itervalues () method does not convert, and it takes the value from the dict in sequence during the iteration

20. The key and value of the iteration dict use the items () or Iteritems () Eg://items () method to convert the Dict object to a list containing a tuple, and iteritems () does not convert the dict to a list, but keeps giving Tuple

21. Generate a list with range (parameter 1, parameter 2) eg:

 

 

Python Learning Essay (detail summary)

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.