Numbers or constants? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Numbers or constants?

For example I need to use the number 3 several times in my code, is it better to use 3 every time or to make a constant with the value of 3? Same with strings f.e., use it like a text every time or make a constant? May be dumb and insignificant but it has been bothering me for some time

30th Apr 2020, 3:04 PM
Ржавый Валенок
Ржавый Валенок - avatar
1 Answer
0
Constant variables are not mutable and what that means that they cannot change during the execution of the code so if you need variables that should not be changed then use the constant if they need to change, you can still use the constants but you will have to copy it to another variable and change it there.
30th Apr 2020, 3:18 PM
rafalzacher1