我知道逻辑上 and
用于 bool 值,如果两个条件都为真,则评估为真,但我对以下语句有疑问:
print "ashish" and "sahil"
it prints out "sahil"?
another example:
return s[0] == s[-1] and checker(s[1:-1])
(taken from recursive function for palindrome string
checking
please explain it and other ways and is oveloaded ,especially what the second statement do.
最佳答案
and
没有重载。
在您的代码中,"ashish"
是一个真值(因为非空字符串是真值),因此它计算 "sahil"
。由于 "sahil"
也是一个真值,因此 "sahil"
返回到 print 语句然后被打印。
关于python - 和python中的操作重载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18644263/