Python OR & AND

These are the Boolean operations, ordered by ascending priority:

OperationResultNotes
x or y if x is false, then y, else x (1)
x and y if x is false, then x, else y (2)
not x if x is false, then True, else False (3)

Priority : () > and > or.           not > and > or

1. x = 1,  y = 2, ( x or y ) == 2       FALSE

cause : x value = true, y value = true.       in OR operation: x = true,  result = x.    (x or y) == x  TRUE.    therefore (x or y)   == 1

2.x = 1,  y = 2, ( x and y ) == 2    TRUE

cause: x value = true, y value = true.       in AND operation: x = true, result = y.     (x and y) == y  TRUE. therefore (x and y) == 2 

 

>>> (x and y) =3
SyntaxError: can't assign to operator

posted on 2017-11-24 16:24  KITEnotKATE  阅读(187)  评论(0)    收藏  举报