- 2021-05-20 16:47
*views 7*- Python

The exam is coming , Have you mastered all these knowledge points ?

1. a += 1 amount to a = a + 1.

2. a, b = 2, 5 amount to a = 2; b = 5.

3. 10/3 The result is 3.33333... What I'm asking is 10 divide 3 Quotient of , Is a floating point decimal .

4. 10//3 The result is 3, What I'm asking is 10 divide 3 Quotient integer part of , Also called floor except .

5. 17%4 The result is 4, Surplus ,17 divide 4 merchant 4, The remainder is 1.

6. 4**2 The result is 16, seek 4 Square of .

7. 3**3 The result is 27, seek 3 Cube of .

8. '@'*8 The result is '@@@@@@@@', express hold @ repeat 8 Get a new string at a time .

9. int(10.5), Decimals 10.5 Convert to integer 10.

10. float(10), Integer 10 Convert to decimal 10.0.

11. int("20"), Put string "20" Convert to integer 20.

12. str(20), Integer 20 Convert to string "20".

13. list a = [ 1, 2, 3, 4, 5, 6, 7],a[0] by 1, Represents the first item in the list ;a[-1] by 7, Represents the last item in the list ;

a[x:y]

Create a new list , Indicates that the list index is x The item to index of is y-1 New list of items . such as ：a[1:5] Indicates that the index is 1 The item to index of is 5-1=4 Item , Namely 2,3,4,5 New list of components [2,3,4,5].

above x If omitted, do not write , Default to 0;y If omitted, do not write , Default to -1. as ：a[:4] The result is [1,2,3,4],a[2:] The result is [3,4,5,6,7].

a[x:y:z] Third parameter z, Represents the interval , Default to 1. as a[::] Result with a equally .a[1:5:2] The result is [2,4]. Find the total length of the list ：len(a).

14. Index operation of string , Similar to list operation . A string , Can be seen as a list of characters . as "about" It can be considered a list ["a", "b", "o", "u",

"t"].

Tuples can be thought of as immutable lists , Index slice , Operations such as finding length are similar to lists .

15. Add an element to the end of the list ：a.append(5).

16. Delete the element at the end of the list ：a.pop().

17. The index value in the delete list is i Element of ：a.pop(i).

18. The value in the delete list is e Element of ：a.remove(e), Only delete e First occurrence position .

19. Judgment element e Are you in the list a in ：e in a, If you're here, you'll get True, be not in False.

20. Determine element e In list a Index value in ：a.index(e), If it doesn't exist , Will report an error , So you need to use it first if e in a Judge .

Example ：

21. Will list a And list b merge ：a+b, Contains duplicate elements .

22. To get a list a Unique element in ：set(a), This is a collection , To convert to a list again , need list(set(a)) Force conversion .

23. following a, b Representative set .

Set is characterized by ： Collection elements are not repeated , The order between elements is not important .

The characteristics of the list are ： List elements can be repeated , The order of elements is important .a - b calculation a and b Difference set of , Namely in a In but not in b A collection of elements in .

24. a | b calculation a and b Union of , Namely in a and b All elements in , Non repeated counting .

25. a & b calculation a and b Intersection of , That is, both in a in , Again b Collection of elements in .

26. a ^ b amount to a | b - (a&b).

Example ：

27. Below a Representative dictionary .

The dictionary is key（ key ） and value（ value ） One to one data type , The key cannot be repeated , And the key must be an immutable object . such as ：a = {'ty': 10, 'cg':

20}. Among them 'ty' Is an immutable string .

28. a.keys() All dictionary keys are returned , But it's not a list type , It needs to be forced to use it outside list(a.keys()) Convert to list .

29. a.values() All dictionary keys are returned , But it's not a list type , It needs to be forced to use it outside list(a.values()) Convert to list .

30. Judgment dictionary a Is there a key in k, use k in a.

Example ：

Technology

- Python172 blogs
- Java151 blogs
- Vue91 blogs
- Flow Chart80 blogs
- C++50 blogs
- algorithm47 blogs
- javascript46 blogs
- programing language43 blogs
- more...

Daily Recommendation

views 11

views 9

views 8

©2020-2021 ioDraw All rights reserved

use Android Studio Designed a simple alarm clock APP use C Language writing bank ATM Code of ATM deposit and withdrawal 2021-11-13JavaScript Hundred refining into Immortals 1.14 Show java_ Guessing games —— The mystery of flow In order to improve work efficiency ： adopt pycharm Template code to reduce duplication of effort The beauty of data visualization -- with Matlab,Python As a tool centos Accidental deletion recovery Binary tree , Full binary tree and complete binary tree --Java Data structures and algorithms 【 Take you to brush with your hands LeetCode】——19. Narcissistic number （ task ）