Commonly used data types in Python include: Number types: including integer (int), long integer (long), float Point type (float), plural type (complex). String type (str): used to save text data. You can use single quotes, double quotes, or triple quotes to define strings. List type (list): Multiple values can be saved. The elements in the list can be of any data type. They are defined using square brackets and separated by commas. Tuple type (tuple): Similar to a list, but the elements in the tuple cannot be modified and are defined using parentheses. Dictionary type (dict): used to save key-value pairs. The key and value can be any data type and are defined using curly brackets. Set type (set): used to save unique elements, defined using braces or the set() function. Boolean type (bool): represents true or false, with only two values: True and False. Empty type (NoneType): represents a null value or empty object. Among them, the first five are commonly used data types. In addition to the above commonly used data types, Python also provides some other data types, such as file types, byte types, date types, etc. Boolean type (bool) in Python The Boolean type (bool) in Python has only two values, namely True and False. The bool type is usually used in logical judgments and conditional control statements, such as while and if statements. In Python, True and False are built-in constants, and both belong to the bool type, and assignment operations are not allowed. You can use the bool() function to convert other types of data into bool type. Overview of numeric types in Python The numeric types in Python include integer (int), long integer ( long), floating point type (float), complex type (complex). Integer type (int): represents the integer type, which can represent positive integers, negative integers and zero. Long integer (long): represents an integer type that is larger than an ordinary integer and can represent very large integers. Floating point type (float): represents a real number type, which can represent decimal decimals, including positive numbers, negative numbers and zero. Floating point numbers have precision limits in Python. Complex: Represents a complex number type, consisting of real numbers and imaginary numbers, such as 3 4j, 2.1-3.2j and other forms. You can use the built-in type() function to check the type of a variable. For example, the following code defines an integer variable, a floating-point variable, and a complex variable respectively: a = 5 b = 3.14 c = 2 + 3j print(type(a)) # 输出: print(type(b)) # 输出: print(type(c)) # 输出:Python's numeric types support a variety of operations, including arithmetic operations, Bit operations, comparison operations, etc. For example, you can use , - , * , / , // , Operators such as % are used to perform arithmetic operations. Use operators such as &, |, ^, ~ etc. Bit operations, use == , != , > , , >= , and other operators perform comparison operations. You can also use the Math module to perform mathematical calculations, such as exponentiation, square roots, trigonometric functions and other operations. Overview of strings in Pyhon Strings in Python are an immutable sequence type. In Python, character sequences enclosed in single quotes, double quotes, or triple quotes are is a string. For example, the following code defines a string variable: my_str = 'Hello, world!'In Python, strings support a variety of operations, such as concatenation, indexing, slicing, traversal, etc. For example, you can use the operator to concatenate two strings, and the [] operator to get the character at a specified position in the string. The following article will explain in detail. Overview of List in Python List in Python is a mutable data type used to save a set of ordered data and can contain elements of various data types, such as Integers, strings, lists, etc. Lists are defined using square brackets []. Elements in the list are separated by commas ,. Elements in the list can be accessed through indexes. For example, the following code defines a list containing elements such as integers, floating point types, and strings: my_list = [1, 2.0, "hello", [3, 4, 5]]The index of the list starts from 0, and you can use subscripts to access the list elements in . To access the first element in my_list, which is the integer 1, you can use my_list[0] to access the first element in my_list Two elements, that is, floating point type 2.0, can be used my_list[1], and so on. 另外,Python 中的列表支持多种操作,如增加元素、删除元素、修改元素、排序等。例如,可以使用 append() 方法向列表末尾添加元素,使用 pop() 方法删除列表中的一个元素,使用切片操作来修改元素等。后续文章详细说明。 Python 中的元组类型(tuple) Python中的元组是一种有序且不可变的序列,用小括号 () 表示。它可以包含不同类型的元素,也可以包含相同类型的元素。元组与列表相似,但是元组中的元素不可修改,因此在需要保证数据不可变的场合,可以使用元组。元组具有以下特点: 元组中的元素不可修改,但是可以通过索引来访问元素,甚至可以使用切片操作来获取子元组。 元组是不可变的,因此可以作为字典的键值。 元组的操作与列表类似,可以进行拼接、重复、求长度等操作。 元组与列表不同,可以在一个元组中包含另一个元组。 总之,元组是一个非常有用的数据类型,在需要保证数据不变而又需要存储多个数据的场合下,它是一个比较好的选择。 Python中的字典(Dictionary) Python中的字典(Dictionary)是一种无序的、可变的映射类型,用大括号 {} 表示。 字典是由键(key)和值(value)组成的一组映射关系,其中键必须是唯一的、不可变的对象,例如字符串、数字或元组,值可以是任意类型的对象。 字典可以用于存储和查找大量的数据,并且支持高效的增、删、改、查等操作。例如,我们可以使用字典来存储一个人的个人信息,如下所示:person = {'name': '张三', 'age': 25, 'gender': '男', 'address': '北京市'}其中,'name'、'age'、'gender'和'address'是键,对应的值分别是'张三'、25、'男'和'北京市'。我们可以使用键来访问其对应的值,如下所示:print(person['name']) # 输出:张三 print(person['age']) # 输出:25总之,字典是Python中非常有用的一种数据类型,它可以应用于很多场景,例如存储配置信息、缓存数据等。 Python中的集合(Set) Python中的集合(Set)是一个无序的、可变的数据类型,用大括号 {} 或 set() 函数表示。 集合可以包含不同类型的元素,且每个元素在集合中都是唯一的。如果需要对一组数据进行去重或判断其是否包含某个元素,可以使用集合。 集合具有以下特点: 集合中的元素是唯一的,如果插入已有的元素,集合中不会有任何变化。 集合是无序的,不能像列表和元组那样使用索引来访问元素。 集合是可变的,可以使用各种方法来增加、删除、更新集合中的元素。 集合可以进行交、并、差等各种集合操作,例如求交集、并集、差集等。 例如,我们可以使用集合来去除列表中的重复元素,如下所示: lst = [1, 2, 3, 4, 5, 1, 2, 3] # 定义一个列表 s = set(lst) # 将列表转化成集合 lst = list(s) # 再将集合转化成列表 print(lst) # 输出:[1, 2, 3, 4, 5]以上代码将列表转化成集合后,再将集合转化成列表,就可以去除列表中的重复元素。 集合也可以用于判断一个元素是否存在于另一个列表或集合中,如下所示:s = set([1, 2, 3, 4, 5]) print(3 in s) # 输出:True print(6 in s) # 输出:False以上代码判断元素3和6是否存在于集合中,并分别输出结果。 总之,集合是Python中非常有用的一种数据类型,它可以用于去除重复元素、判断元素是否存在等各种场合。 Python中的空类型 NoneType 在Python中,NoneType 是一个表示空值的数据类型,它只有一个取值None。 NoneType通常用于表示一个不存在的对象或变量的空值,例如一个函数没有返回值时,它默认返回None。 NoneType还可以用于初始化变量,表示该变量还没有被赋值。 在Python中,None是内置的常量,表示空值。可以使用type()函数来判断一个变量的类型,如下所示:x = None print(type(x)) # 输出:以上代码定义了一个变量x,并将其赋值为None,然后使用type()函数来判断x的类型,结果输出。 NoneType还常常用于函数的返回值,如果函数没有明确的返回值,则默认返回None,例如:def hello(): print('Hello, world!') x = hello() print(x) # 输出:None以上代码定义了一个函数hello(),该函数没有明确的返回值,因此默认返回None。在函数调用时,将返回值赋值给变量x,然后输出变量x的值,结果输出None。