Why do In-place operators allow you to write code like 'x = x + 3' as 'x += 3'? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

Why do In-place operators allow you to write code like 'x = x + 3' as 'x += 3'?

Why are operators such as 'x = x + 3' represented as 'x += 3'? Coming from FORTRAN, I find that the representation of in-place operators that Python uses is very confusing. Is there a reason?

14th May 2018, 11:49 AM
Jujar Panesar
1 ответ
0
With Python, the code needs to be read, understood, and then executed so making the code more concise makes it run faster. Other languages added the conciseness prior to optimizations being available to do it automatically. Fortran had the advantage of being the first language supporting optimizations so didn't need language support.
14th May 2018, 3:15 PM
John Wells
John Wells - avatar