test_str="www.baidu.com"
test_list=[1,"d",5]
test_list1=[2,4,"n","t",3]
test_dict={"name":"dnt","wechat":"xxx"}
##################### 运算符扩展 #####################
# + 合并 (不支持字典)
print(test_str+test_str)
print(test_list+test_list1)
www.baidu.comwww.baidu.com [1, 'd', 5, 2, 4, 'n', 't', 3]
# * 复制 (不支持字典)
print(test_str*2)
print(test_list*2)
www.baidu.comwww.baidu.com [1, 'd', 5, 1, 'd', 5]
# in 是否存在(字典是查key)
print("d" in test_str) #True
print("d" in test_list) #True
print("d" in test_dict) #False
print("name" in test_dict) #True
True True False True
# not in 是否不存在(字典是查key)
print("z" not in test_str) #True
print("z" not in test_list) #True
print("z" not in test_dict) #True
print("name" not in test_dict) #False
True True True False
################# 内置函数扩展:(len,max,min,del) #################
# len(item) 计算容器中元素个数
print(len(test_str))
print(len(test_list))
print(len(test_dict))
13 3 2
# max(item) 返回容器中元素最大值
max(test_str)
'w'
# 这个注意一种情况(当然了,你按照之前说的规范,list里面放同一种类型就不会出错了)
max(test_list) #TypeError: '>' not supported between instances of 'str' and 'int'
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-10-7da4501a78c2> in <module>() 1 # 这个注意一种情况(当然了,你按照之前说的规范,list里面放同一种类型就不会出错了) ----> 2 max(test_list) #TypeError: '>' not supported between instances of 'str' and 'int' TypeError: '>' not supported between instances of 'str' and 'int'
test_list=[1,3,5,7,9,2]
print(max(test_list))
print(max(test_dict)) #比较key
9 wechat
# min(item) 返回容器中元素最小值
print(min(test_str))
print(min(test_list))
print(min(test_dict))
. 1 name
# del(item) 删除变量
# del() or del xxx
# 可以忽略 cmp(item1, item2) 比较两个值
# Python2里面有 cmp(1,2) ==> -1
# cmp在比较字典数据时,先比较键,再比较值