公共操作 -- 运算符
作者:互联网
1、运算符
s1 = 'asd' s2 = 'hgf' list1 = [1, 2] list2 = [3, 4] t1 = (4, 5) t2 = (6, 7) dict1 = {11: 22} dict2 = {44: 55} # 结果:asdhgf print(s1 + s2) # 结果:[1, 2, 3, 4] print(list1 + list2) # 结果:(4, 5, 6, 7) print(t1 + t2) # 结果:报错(不支持字典) print(dict1 + dict2)
str1 = 'a' list3 = ['hallo'] t1 = ('abc') # 打印10个- # 结果:---------- print('-' * 10) # 结果:aaaaa print(str1 * 5) # 结果:['hallo', 'hallo', 'hallo', 'hallo', 'hallo'] print(list3 * 5) # 结果:abcabcabcabcabc print(t1 * 5)
str2 = 'abcd' list4 = [10, 20, 30] t4 = (100, 200, 300) dict4 = {'name': 'abc', 'age': '50'} # 1.字符b是否存在 # 结果:True print('b' in str2) # 结果:False print('c' not in str2) # 2.数据10是否存在 # 结果:True print(10 in list4) # 结果:False print(10 not in list4) # 3.100是否存在 # 结果:False print(100 not in t4) # 结果:True print(100 in t4) # 4.name是否存在 # 结果:True print('name' in dict4) # 结果:False print('name' not in dict4) # 结果:True print('name' in dict4.keys()) # 结果:False print('name' in dict4.values())
标签:hallo,name,结果,--,运算符,公共,print,True,10 来源: https://www.cnblogs.com/yz-b/p/16637804.html