在运算操作和内建函数返回Boolean结果0或者Flase表示false
1或True表示true
python中的Boolean运算如下:
print('x or y -> if x is false,then y, else x ') x, y = 2, 0 print('{} or {} = {}'.format(x, y, x or y)) x1, y1 = 0, 10 print('{} or {} = {}'.format(x1, y1, x1 or y1)) x2, y2 = 0, 0 print('{} or {} = {}'.format(x2, y2, x2 or y2)) print('#' * 50) print('x and y -> if x is false,then x, else y ') print('{} and {} = {}'.format(x, y, x and y)) x1, y1 = 0, 10 print('{} and {} = {}'.format(x1, y1, x1 and y1)) x2, y2 = 0, 0 print('{} and {} = {}'.format(x2, y2, x2 and y2)) print('#' * 50) print('not x -> if x is false,then True,else False ') x = 2 print('not {} = {}'.format(x, not x)) x = 0 print('not {} = {}'.format(x, not x))
##################################################
not x -> if x is false,then True,else False
not 2 = False
not 0 = True
>>>
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did86732