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):

2nd Jul 2020, 8:53 PM
Muh'd Mustafa Ibrahim
Muh'd Mustafa Ibrahim - avatar
7 Antworten
+ 2
Muh'd Mustafa Ibrahim We can write with or without parenthesis.
2nd Jul 2020, 9:51 PM
A͢J
A͢J - avatar
+ 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.
2nd Jul 2020, 10:39 PM
HonFu
HonFu - avatar
+ 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
4th Jul 2020, 6:32 PM
kiran k suthar
kiran k suthar - avatar
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.
3rd Jul 2020, 3:47 AM
SSki11
SSki11 - avatar
- 1
i cannot say anything
2nd Jul 2020, 11:23 PM
Ibrahim Abdullahi Sokoto
Ibrahim Abdullahi Sokoto - avatar