The concept and usage of basic data types (List, Tuple, Dict) in Python

There are many data types in Python. Today Xiaoqian will introduce three of them, lists, tuples, dictionaries and their concepts and usage. You will understand after reading them.

1. List

First of all, List is included with [], and each element is separated by a (comma). Any data type can be nested in List, and data types can be nested within each other (except for set), such as:
Insert picture description here
the value of a list
Insert picture description here

List modification
Insert picture description here

List delete
Insert picture description here

List insertion
Insert picture description here

List query
Insert picture description here

List reverse
Insert picture description here

List sort, maximum (small) value
Insert picture description here

Conversion between lists and strings
Insert picture description here

Two, tuple

The tuple is an immutable type, the value cannot be changed according to the index, and cannot be added or deleted. The tuple is included with (), such as:
Insert picture description here

Tuples can also be indexed, sliced, and traversed. I will not demonstrate here.
There are two methods:
Insert picture description here

Tips:
Tuples are also parentheses, which look the same as the method. In order to facilitate the distinction and make it more intuitive, we generally add a comma after it. This is a good specification..., such as: tu = (1,2,3,)

Three, dictionary

The dictionary uses {} to include key-value pairs composed of key and value. The dictionary is an unordered list of sets. The dictionary cannot be used as the key value. The key value can only be unique. The dictionary can still nest other data types, such as:
Insert picture description here

Value
Insert picture description here

Traverse If
Insert picture description here
you want to know more about Python technology, welcome to follow me!

Guess you like

Origin blog.csdn.net/xiaoxijinger/article/details/114821931