python判断字符串是否相同

2022-10-17 10:49:28
# 一定要使用 == 不能使用 is 。两个字符串内存地址不可能相同 (用id(str)查看字符串所占用的内存空间)from functoolsimportreducedefqww(q,p):print(reduce(lambda x, y:Trueif x== yelseFalse,(str(q),str(p))))

qww(1,11)

此法看似很牛批,实际上就是闲着没事装逼而已

下面是简单写法

defqww(x,y):if x==y:returnTrueelse:returnFalseprint(qww(1,1))

或者使用lambda表达式更加简单

qww=lambda x,y:Trueif x==yelseFalseprint(qww(1,1))
  • 作者:JHC000000
  • 原文链接:https://blog.csdn.net/CXY00000/article/details/122398866
    更新时间:2022-10-17 10:49:28