+ 1

Tell me why, plz

print( True or False and False) print(( True or False) and False) print( False and False or True) The result is: True Flase True

13th Jul 2020, 12:55 AM
Ryan
4 Antworten
+ 4
both operands of an 'and' comparison have to be True to return True if either operand of an 'or' comparison are True the True is returned 'and' has higher operator precedence than 'or' True or False = True False and False = False True or False and False = True or False = True () has higher operator precedence than 'and', 'or' (True or False) and False = True and False = False False and False or True = False or True = True
13th Jul 2020, 1:08 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
If you have remember this in such way let True =1 ,False=0 ,and = * and or = + , so * has more precedence then + . But always solve first inside perenthesis problem then you can solve outer. print (1+0*0) print ((1+0)*0) print (0*0+1) Output 👇👇 1= true 0= false 1= true
13th Jul 2020, 1:09 AM
Sâñtôsh
Sâñtôsh - avatar
+ 2
According to operator precedence the and has higher precedence then or so in Case1. False and False is equal to false because it will only return true when both will be true and then it becomes true or false . Or will return true if any one of them is true so here in true or false "true" is present so the final result is true. Case2. Parenthesis "()" have higher precedence then "and" so (True or False) will exicuted first and will give true because one of them is true and then same process. finally true and false which will result in False Case3. Similar to case1 only the order is changed
13th Jul 2020, 1:15 AM
Ayush Kumar
Ayush Kumar - avatar
0
To understand the results, you have to understand logic and order of precedence / operations. For this code, the rules to follow are: 1. Solve 'and' before 'or'. 2. Solve the inner 'bracket / parenthesis' first before the outer bracket. 3. Solve 'and' before 'or'.
13th Jul 2020, 9:39 PM
Oluwatosin
Oluwatosin - avatar