Does my variable name need to match the math I’m doing?


#1

Question

Most of the variable names in these exercises match the math being done in the value they’re assigned.

Answer

Your variable can be named anything you like! You could name a variable addition and then set its value as the addition of two numbers, or you could just as easily name it twoNumbers.

However, it’s definitely helpful to anyone reading your code (including you) if you name your variables in a way that is unambiguous and descriptive. For example, naming a variable x may be short and sweet, but it tells me absolutely nothing about the value it holds or what it’s meant for. If we have a variable named degrees_celsius, it seems likely that it would hold some number that is the temperature in celsius. Much better!


FAQ: Learn Python - Python Syntax - Arithmetic