Learning is like building blocks. You have the basic building blocks before you can build complex models. This is especially true when learning programming. Strings, lists, dictionaries, tuples, and collections in Python are the most commonly used basic skills and must be asked in interviews and written tests. In order to facilitate comparative study, I organized strings, lists, dictionaries, tuples and sets into a mind map, hoping to help you master the use of these data types faster.
For some basic concepts about data types, you can take a look at this article:
Basic Python data types in detail
1. The string
A string is the most commonly used data type in Python. It is a data type that holds sequences of characters whose elements can only be characters. Strings are represented by single or double quotation marks.
Python string manipulation
List 2.
A list is a data type used to hold bulk data. The index of a list is similar to, but not identical to, the index of a string, because a list can be modified, so we can modify a list through the index of a list.
The most comprehensive summary of Python list operations
3. The dictionary
A dictionary is a type of mapping consisting of key-value pairs, where the keys of the dictionary must be hashable (that is, immutable) and cannot have the same key name within the same dictionary; The value of a dictionary can be of any type, and the value of a dictionary can be repeated.
Summary of Python dictionary operations
4. A tuple
Python tuples are similar to lists, except that the elements of a tuple cannot be modified. Tuples use parentheses and lists use square brackets.
Benefits of using tuples:
- Unmodifiable, write protected, safe, python built-in function return types are all tuples
- Tuples are more space – saving and efficient than lists
Collection of 5.
A collection object is an unordered set of hashable values (that is, the elements in the collection are immutable types, so mutable objects such as lists and dictionaries cannot be members of the collection).
A collection is an unordered collection of non-repeating elements. You can use curly braces {} or the set() function to create a collection. Note: to create an empty collection, se() must be used instead of {}, because {} is used to create an empty dictionary.
Click the link to get the full mind map!