Module 02 · Python Data StructuresPython 数据结构
Module 2 Summary: Python Data Structures模块 2 总结:Python 数据结构
Congratulations! You have completed this module. At this point, you know that:
恭喜!您已完成本模块。此时,您知道:
- In Python, we often use tuples to group related data together. Tuples refer to ordered and immutable collections of elements.
在 Python 中,我们经常使用元组来将相关数据分组在一起。元组指的是有序且不可变的元素集合。 - Tuples are usually written as comma-separated elements in parentheses “()".
元组通常写作括号“()”中逗号分隔的元素。 - You can include strings, integers, and floats in tuples and access them using both positive and negative indices.
您可以在元组中包含字符串、整数和浮点数,并使用正负索引访问它们。 - You can perform operations such as combining, concatenating, and slicing on tuples.
您可以执行合并、连接和切片等操作。 - Tuples are immutable, so you need to create a new tuple to manipulate it.
元组是不可变的,因此您需要创建一个新的元组来操作它。 - Tuples, termed nesting, can include other tuples of complex data types.
元组,称为嵌套,可以包含其他复杂数据类型的元组。 - You can access elements in a nested tuple through indexing.
您可以通过索引访问嵌套元组中的元素。 - Lists in Python contain ordered collections of items that can hold elements of different types and are mutable, allowing for versatile data storage and manipulation.
Python 中的列表包含有序的项目集合,可以存储不同类型的元素,并且是可变的,允许进行灵活的数据存储和处理。 - A list is an ordered sequence, represented with square brackets "[]".
列表是有序序列,用方括号“[]”表示。 - Lists possess mutability, rendering them akin to tuples.
列表具有可变性,使其类似于元组。 - A list can contain strings, integers, and floats; you can nest lists within it.
列表可以包含字符串、整数和浮点数;你可以在其中嵌套列表。 - You can access each element in a list using both positive and negative indexing.
您可以使用正负索引来访问列表中的每个元素。 - Concatenating or appending a list will result in the modification of the same list.
连接或追加列表将导致同一列表的修改。 - You can perform operations such as adding, deleting, splitting, and so forth on a list.
您可以在列表上执行添加、删除、分割等操作。 - You can separate elements in a list using delimiters.
您可以使用分隔符来分隔列表中的元素。 - Aliasing occurs when multiple names refer to the same object.
别名发生在多个名称指向同一对象时。 - You can also clone a list to create another list.
您也可以克隆一个列表以创建另一个列表。 - Dictionaries in Python are key-value pairs that provide a flexible way to store and retrieve data based on unique keys.
Python 中的字典是键值对,提供了一种灵活的方式来根据唯一的键存储和检索数据。 - Dictionaries consist of keys and values, both composed of string elements.
字典由键和值组成,两者均由字符串元素构成。 - You denote dictionaries using curly brackets.
您使用花括号表示字典。 - The keys necessitate immutability and uniqueness.
键需要不可变性和唯一性。 - The values may be either immutable or mutable, and they allow duplicates.
值可以是不可变的或可变的,并且允许重复。 - You separate each key-value pair with a comma, and you can use color highlighting to make the key more visible.
您使用逗号分隔每个键值对,并且可以使用颜色高亮来使键更易于识别。 - You can assign dictionaries to a variable.
您可以将字典分配给一个变量。 - You use the key as an argument to retrieve the corresponding value.
您使用键作为参数来检索相应的值。 - You can make additions and deletions to dictionaries.
您可以对字典进行添加和删除操作。 - You can perform an operation on a dictionary to check the key, which results in a true or false output.
您可以对字典执行操作以检查键,这将产生真或假的输出。 - You can apply methods to obtain a list of keys and values in a dictionary.
您可以将方法应用于获取字典中的键和值列表。 - Sets in Python are collections of unique elements, useful for tasks such as removing duplicates and performing set operations like union and intersection. Sets lack order.
Python 中的集合是一组唯一的元素集合,用于执行如去除重复项和执行并集、交集等集合操作的任务。集合没有顺序。 - Curly brackets "{}" are helpful for defining elements of a set.
花括号 "{}" 有助于定义集合的元素。 - Sets do not contain duplicate items.
集合不包含重复项。 - A list passed through the set function generates a set containing unique elements.
一个通过集合函数传递的列表生成包含唯一元素的集合。 - You use “Set Operations” to perform actions such as adding, removing, and verifying elements in a set.
您使用“集合运算”来执行添加、删除和验证集合中元素等操作。 - You can combine sets using the ampersand "&" operator to obtain the common elements from both sets.
您可以使用“&”运算符组合集合,以获取两个集合的共同元素。 - You can use the Union function to combine two sets, including both the common and unique elements from both sets.
您可以使用并集函数合并两个集合,包括两个集合中的公共和独特元素。 - The sub-set method is used to determine if two or more sets are subsets.
子集法用于确定两个或多个集合是否为子集。