The name we give a variable, also called its identifier, is subject to some important rules. Some of these rules are strict - Python will not accept names that do not follow these rules. These rules are part of the syntax of Python. The syntax of a language is the rules for what are valid ways to write things in the language. Other rules for variable names are human conventions. Python will not enforce these rules, but you and other programmers reading your code may get confused.
Python has a few dozen keywords that you can’t use as variable names. Here is a list of the most common ones. If you ever have an error based on one of your variable names and do not know why, compare your name to this list to make sure you are not using a keyword as your name.
Since you can’t have spaces in names, one way to make variable names easier to read is to use camel case (uppercase the first letter of each new word).
Programmers generally choose names for their variables that are meaningful to the human readers of the program — they help the programmer document, or remember, what the variable is used for. To be meaningful, a name must clearly describe what a piece of information is to anyone reading the code, not just the author of the code.
Meaningful names are generally full words like height. Abbreviations are generally not meaningful to anyone other than the original author. If you are reading through code and see a variable h, that will likely not do anything to help you figure out what information it is holding. (The exception to this rule is representing values from a mathematical formula like \(a^b + b^c = c^2\) where a has a well-defined meaning.)
Oftentimes, you need multiple words to meaningfully describe a variable. Say you have a program that involves converting a height between inches and centimeters, within that program, the name height might be confusing. Is it referring to a value in inches? centimeters?
In cases like this, since you can’t have spaces in a variable name, you can either join words together by uppercasing the first letter of each new word like heightInInches (called mixed-case or camel-case because the capitals look like the humps of a camel) or use underscores between words like height_in_inches (called snake-case).
date isn’t the worst option here, but it might not be clear to other readers of the code what date we are referring to. Is it a person’s hire date? their birthday? today’s date?
Beginners sometimes confuse “meaningful to the human readers” with “meaningful to the computer”. So they’ll wrongly think that because they’ve called some variable average or pi, it will somehow automagically calculate an average, or automagically associate the variable pi with the value 3.14159.
That is not the case. The computer doesn’t attach semantic meaning to your variable names. The Python interpreter does not care if you call a variable average, a, something, or sue - to it, all of those names are equally meaningful in that they have no real meaning other than naming a value the programmer is working with.