Home > other >  Introduction to python
Introduction to python

Time:03-16

1. The list is an ordered set, there is no fixed size, can save the Python objects with any number of any type, grammar for [elements of elements 1, 2,..., n],
(1) the key point is (brackets []) and (comma,)
(2) brackets put all the elements together
(3) a comma to separate each element one by one
Note: a. As a result of the list elements can be any object, so the list is saved by the pointer to the object, even save a simple [1, 2, 3], there are also three Pointers and three integer object,
X=[a] * 4 operations, just four points to create a list of references, so once a change, x 4 a will change too,
B. don't like tuples, list contents can be changed (mutable), so the additional (append, extend), insert (insert), delete (remove, pop) these operations can be used to it,
2. Delete the elements in the list
List. Remove (obj) to remove the list a value in the first match
3. To obtain a list of the elements in the
- by the index of the element value, access to a single element from a list, note that the list of index values from 0,
- through will specify the index to 1, can let a Python list returns the last element, the index return - 2 list penultimate element, and so on,
4. A list of common operators
The equality operator:==
Connect the operator +
Repeat the * operator
Membership operators in, not in
(===), only members, members all at the same time to return True,
5. There are two ways to get the list together with (a plus) and the multiplication sign (*), the former fore and aft, the latter replication,
Ey, is mainly used to compare the elements, only one parameter, the specific parameters of the function is derived from object iteration, an element of the specified object iteration to sort,
Reverse - collation, reverse=True descending, reverse=False ascending (default),
This method has no return value, but on the list of objects to sort,
  • Related