Why is this code not just be written without the parenthesis like this: | SoloLearn: Learn to code for FREE!

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/2020 8:53:18 PM

Muh'd Mustafa Ibrahim

7 Answers

New Answer

+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.

0

Muh'd Mustafa Ibrahim Using parentheses is a good practice to avoid any mistakes while calculating an expression See the example below 👇 6+4/2 Result : 8.0 (6+4)/2 Result : 5.0

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.

0

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

-1

i cannot say anything