数据类型
| 单 词 | 意思 | 音 标 |
|---|---|---|
| parentheses | 括号 | /pəˈrenθəsiːz/ |
| Tuple | 元组 | /tjʊpəl; ˈtʌpəl |
| Syntax | 语法 | /ˈsɪntæks/ |
| curly braces | 花括号 | ˈbreɪsɪz |
| indices | 索引 | /ˈɪndɪsiːz/ |
| mutable | 可变的 | ˈmjuːtəb(ə)l |
| intersection | 交集 | /ˌɪntəˈsekʃn/ |
各种数据类型
**Lists **
Ordered collection of arbitrary objects.
任意对象的有序集合。
| 单 词 | 意思 | 音 标 |
|---|---|---|
| Elements | 元素 | |
| offset | 偏移量 | |
| Variable | 可变的 | |
| arbitrarily nestable | 任意嵌套 | /ˌɑːbɪˈtrerəli/ , /ˈnestəbl/ |
| grow and shrink | 增长和缩小 | /ʃrɪŋk/ |
| Elements enclosed in square brackets. | 包含在方括号中的元素。 | /ɪnˈkləʊzd/ /ˈbrækɪts/ |
| commas | 逗号 | /ˈkɒməz/ |
| Indexing | 索引 | |
| built-in function | 内置函数 | |
| Stack | 堆叠 | /stæk/ |
| descending | 降序 | /dɪˈsendɪŋ/ |
| inplace | 就地 |
Lists的运算
| 运算 | 例子 |
|---|---|
| create | name=["wang","liping","xiaozhang",1,8] |
| Indexing | name[0] |
| Slicing Lists | name[:9] |
| name[1:9] | |
| name[1:2] | |
| len | len(name) |
| Polymorphism with Lists, use + or * | list=["A"] new_list=list+[0] 结果[‘A’, 0] |
| new_list=list*3 new_list [‘A’, ‘A’, ‘A’] | |
| in or not in | "A" in new_list |
| "A" not in new_list | |
| sort | list=[1,2,3,6,7,1,0] sorted(list) [0, 1, 1, 2, 3, 6, 7] |
| 降序排列 descending | sorted(list,reverse=True) [7, 6, 3, 2, 1, 1, 0] |
| sum | ![]() |
**Nested Lists **
| 运算 | 例子 |
|---|---|
| create | nested_L= [ [1,2,3],[‘A’,’B’,’C’] ] nested_L[1] |
| pick out the 2 in the first list | nested_L[0][1] |
Tuple
An ordered, immutable collection of items.
Created with parentheses ()
Key Characteristics
Ordered: Like lists, items are indexed.
Immutable:You cannot change, add, or remove items once the tuple is created.
| 函数 | 举例 | 输出 |
|---|---|---|
| my_tuple=(1,2,3,"q","q",1) | ||
| Indexing | print(my_tuple[0]) | 1 |
| Length | print(len(my_tuple)) | 6 |
| Membership | print(2 in my_tuple) | true |
| Concatenation | print(my_tuple + (3,4)) | (1, 2, 3, ‘q’, ‘q’, 1, 3, 4) |
| Counts occurrences of an item | print(my_tuple.count(1)) | 2 |
![]() |
Dictionary
An unordered, mutable collection of key-value pairs.
Syntax: Created with curly braces {}.
Key Characteristics
Unordered: Items don’t have a fixed order (in older Python versions). Accessed by keys, not indices.
Mutable: You can change, add, or remove key-value pairs.
| 函数 | 举例 | 输出 |
|---|---|---|
| my_dic={"name":"xiaozhao","age":23} | ||
| Indexing | print(my_dic["name"]) | xiaozhao |
| Key Membership | print("age" in my_dic) | True |
| change | my_dic["name"]="张三" | {‘name’: ‘张三’, ‘age’: 23, ‘address’: ‘Dublin’} |
| Adding a new key-value | my_dic["address"]="Dublin" print(my_dic) | {‘name’: ‘张三’, ‘age’: 23, ‘address’: ‘Dublin’} |
| Removes a key-value pair | my_dic.pop("name") print(my_dic) | {‘age’: 23, ‘address’: ‘Dublin’} |
| Returns all keys | print(my_dic.keys()) | dict_keys([‘age’, ‘address’]) |

Set
An unordered, mutable collection of unique items.
Syntax: Created with curly braces {} or the set() function.
Key Characteristics
Unordered: Items don’t have a fixed order.
Mutable: You can add or remove items.
Unique: Duplicate items are automatically removed.
| 函数 | 举例 | 输出 |
|---|---|---|
| create | set_numbers=set([1,2,2,3,4]) | {1, 2, 3, 4} |
| set_str=set("hello") | ||
| set1={1,2,3,4,5,5,6} | ||
| union | set2={5,6,7,8,9} print(set1 | set2) |
| intersection | print(set1 & set2) | {5, 6} |
| membership | print(1 in set1) | True |
| add or remove | set1.add(100) set1.remove(1) print(set1) | {2, 3, 4, 5, 6, 100} |
![]() |


