0
Why is this code not just be written without the parenthesis like this:
if 1 == 1 and 2 + 2 > 3: Rather than: if (1 == 1) and (2 + 2 > 3):
7 ответов
+ 2
Muh'd Mustafa Ibrahim We can write with or without parenthesis.
+ 2
Every language has their own operator precedence.
If you know it well, you can do without parentheses in many cases, like here where they make no difference.
Sometimes coders use parentheses anyway to make sure they don't accidentally misjudge it - that could lead to annoying bugs.
Or they want to make life easier for someone reading the code, so that they don't have to wonder 'How was the order of operations again?' but can just read the code directly.
+ 1
One more thing if you are using 2.x version then there is parenthesis compulsory
And if you are using version 3.x then no need of it
0
Muh'd Mustafa Ibrahim , I don't think there is any difference in the above two; both work well. However, I'd suggest you to make use of parentheses not only to beautify the code or avoid mistakes, but to also make it easier to read and understand the logic.
- 1
i cannot say anything