List commonly used built-in functions

1. x in s:
returns true: if there are elements in the list s,
returns false: if there are no elements x

 

2. x not in s:
returns true: if there is no element in the list s,
returns false: if there is an element x

 

3. s + t:
connect list s and list t.

 

4. s * n or n * s:
repeat the list s n times

 

5. s [i]:
returns the i-th element in the list s, the subscript starts from 0

 

6. s [i: j]:
intercept the subscript from i to j, including i but not j

 

7. s [i: j: k]:
intercept the subscript from i to j, but each step spans k

 

8. len (s):
returns the number of elements in the list s

 

9. min (s):
returns the minimum value in the list s

 

10. max (s):
returns the maximum value in the list s

 

11. s.index (x [, i [, j]):
Returns the subscript position of the first x in the s list (or the subscript is between i and j, the subscript position of the first x appears)

 

12. s.count (x):
the number of elements x in the list s

 

13. s [i] = x:
Assign x to the ith position of the list s.

 

14. s [i: j] = t:
replace the elements from i to j in the list s with iterable t.

 

15. del s [i: j]:
Delete the elements from i to j in the list s. Similar to s [i: j] = []

 

16. s [i: j: k] = t:
replace the elements in the list s starting from i and stepping with a tail k until the elements in j are replaced by the elements in t.

 

17. s.append (x):
append element x to the end of the list s, similar to s [len (s): len (s)] = [x]

 

18. s.clear:
all elements in case s, similar to del s [:]

 

19. s.copy:
returns a shallow copy of the list s

 

20. s.extend (t) or s + = t:
extend s with the content of t

 

21. s.insert (i, x):
Insert element x at position i, similar to s [i: i] = [x]

 

22. s.pop (i):
returns the element at the ith position, and deletes the element from s

 

23. s.remove (x):
delete the first x in s

 

24. The elements in list s.reverse ()
are reversed.

 

25 s.sort (*, key = None, reverse = False):
sort the elements in s, use the comparison symbol '<', if the elements are not comparable, it will sound wrong. When reverse is True, use the comparison symbol '>'.

Guess you like

Origin www.cnblogs.com/panweiwei/p/12757776.html