Is it necessary to learn the operation precedence? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

Is it necessary to learn the operation precedence?

I mean do I have to learn which one should be considered first and which one later. For example: parenthesis is greater than multiplication. Do I really need to learn them? Brackets can be used instead of learning them. if x == y or z and d == 2: ... Instead of this I can easily write if (x == (y or z)) and (d == 2): ... It make sense and does not leave any kind of confusion. Please explain should I invest my time on it or should I use parenthesis instead for simplicity

5th Jul 2020, 3:03 PM
Zabir Abdullah
Zabir Abdullah - avatar
3 Respuestas
+ 9
Zabir Abdullah It depends on usage according to me. If you want to use normally for if-else statement you don't need as simply you can do that with use of brackets. But when it comes to complex Math related equations then this will come handy coz different use of precedence creates different answers. Also learning such topics will help you in creating algorithm like in regex or Data structures to solve math equations etc.
5th Jul 2020, 3:25 PM
Ketan [#Be Happy 😄]
Ketan [#Be Happy 😄] - avatar
+ 2
man using bracket is the way of making using code easy to debug and understand by other its all on u but the questions in interview may stuck u in this concepts if those were asked.... So i prefer to learn them becoz having more knowledge is great and Fun B-)
5th Jul 2020, 3:10 PM
Abhay
Abhay - avatar
0
Sometimes braces can increase the readability. Especially if they are getting more complex and if you're using meaningful names. E.g. if (age >= 18) or (parentalPermission && parentsAge >= 18).
5th Jul 2020, 3:17 PM
Sandra Meyer
Sandra Meyer - avatar