Q. Practice the following expressions:
a = ''(empty string)
b = ''
c = 'great'
d = 'Great'
e = 'GREAT'
f = 'Great'
g = 'GREAT'
h = 'great'
| S. No. | Expression | Result | Reason |
|---|---|---|---|
| 1 | a or c | ||
| 2 | c or a | ||
| 3 | a and c | ||
| 4 | c and a | ||
| 5 | f == g or f == d | ||
| 6 | f or g | ||
| 7 | f or d | ||
| 8 | d or f | ||
| 9 | c == h and e == g | ||
| 10 | a and g | ||
| 11 | c or g | ||
| 12 | g or c | ||
| 13 | g and a | ||
| 14 | a or g | ||
| 15 | g or a |
Answer :-
Note :- In python ‘0’ and ‘’ (empty string) treated as False and all other number (e.g. 1, 1.3652, -9.25, 6, 0.0001 ) and “ABC…” treated as True.
| S. No. | Expression | Result | Reason |
|---|---|---|---|
| 1 | a or c | 'great' | In or operator if one of them is True value than it will return True. |
| 2 | c or a | 'great' | In or operator if one of them is True value than it will return True. |
| 3 | a and c | '' | In and operator if any value is false then it will return False. |
| 4 | c and a | '' | In and operator if any value is false then it will return False. |
| 5 | f == g or f == d | True | In or operator if one of them is True value than it will return True. |
| 6 | f or g | 'Great' | In or operator if both value is true then it will return first value. |
| 7 | f or d | 'Great' | In or operator if both value is true then it will return first value. |
| 8 | d or f | 'Great' | In or operator if both value is true then it will return first value. |
| 9 | c == h and e == g | True | If both values is True in and operator then it will return True. |
| 10 | a and g | '' | If one value is false then and operator return False. |
| 11 | c or g | 'great' | In or operator if both value is true then it will return first value. |
| 12 | g or c | 'GREAT' | In or operator if both value is true then it will return first value. |
| 13 | g and a | '' | If one value is false then and operator return False. |
| 14 | a or g | 'GREAT' | If one value is true in or operator then it will return True |
| 15 | g or a | 'GREAT' | If one value is true in or operator then it will return True |
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )