1.交换两个变量的值
a,b=10,5
print(a,b)
a,b=b,a
print(a,b)
2.查找列表中频率最高的值
li=[1,1,2,2,3,3,3,4,4]
print(max(set(li),key=li.count))
#这个方法打印出来的结果,是会将列表中所有出现过的元素,以(元素,个数)的元组形式,从多到少组成一个列表给你展现出来
from collections import Counter
countor=Counter(li)
print(countor.most_common(5))
3.将列表中的字符串连接起来
a=['a','b','c']
print("".join(a))
4.检查两个字符是不是由相同的字母不同顺序组成
from collections import Counter
str1='python'
str2='nohtyp'
print(Counter(str1)==Counter(str2))
5.链式函数调用
def multi(a,b):
return a*b
def add(a,b):
return a+b
print((multi if True else add)(5,7))