公共操作
公共操作
运算符
运算符 | 描述 | 支持的容器类型 |
---|---|---|
+ | 合并 | 字符串、列表、元组 |
* | 复制 | 字符串、列表、元组 |
in | 元素是否存在 | 字符串、列表、元组、字典 |
not in | 元素是否不存在 | 字符串、列表、元组、字典 |
str1 = 'aa'
str2 = 'bb'
list1 = [1, 2]
list2 = [10, 20]
t1 = (1, 2)
t2 = (10, 20)
print(str1 + str2) # aabb
print(list1 + list2) #[1, 2, 10, 20]
print(t1 + t2) # (1, 2, 10, 20)
str1 = 'a'
list1 = ['hello']
t1 = ('world',)
print(a * 5) # aaaaa
print(list1 * 5) #['hello', 'hello', 'hello', 'hello', 'hello']
print(t1 * 5) #('world', 'world', 'world', 'world', 'world')