Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - String, list, integer, which one has an index?
String, list, integer, which one has an index?
Today's rookie learned lists, tuples, dictionaries, sets and strings. In general, these container type variables have the following characteristics:

String, tuple and list all belong to sequence type, and the sequence is indexed by continuous integers. Numeric values, characters and tuples are immutable types. Lists, collections and dictionaries are all mutable types. You can delete, update, copy, add and access elements. Note that indexing, slicing, addition, and multiplication operations are not supported by collections and dictionaries.

Write down today's notes:

Tips:

1, comma and the following code need to be separated by spaces, so that the compiler will not warn and the code will look better.

2. About the list:

The list index is zero-based.

The difference between del and pop is that the former directly deletes elements, while the latter can return the deleted elements to variables, and the variables can be reused. You can use the list () function to convert other contents into a list.

3. About tuples:

X = (1,) and x = (1)

When a tuple has only one element, it must be added, otherwise parentheses are regarded as operators. The former outputs (1,) and the latter outputs 1.

..................................................................................................................................................................................

1) creates two tuples in succession, which can be called a list, as follows:

x = ( 1, 10.3 1,' python '),(' data ', 1 1)

Print (x[0])

Output (1, 10.3 1,' python')

2) After the tuple is created, the elements cannot be changed, but the list elements can be changed.

4. About dictionaries:

Dictionary is the only mapping type in Python, and dictionaries are indexed by "keywords". There are two attributes, one is the key (cannot be saved) and the other is the value of the corresponding key (can be empty).

5. About collection:

Python also has a set of immutable elements, that is, elements cannot be added or deleted, and the type is called frozenset. Frozenset can still perform collection operations, but it cannot use methods with update.

6. About character strings