Correct and incorrect variable names
Note that the same restrictions apply to function names.
Python does not impose restrictions on the length of variable names, but that doesn't mean that a long variable name is always better than a short one.
Here are some correct, but not always convenient variable names:
MyVariable, i, t34, Exchange_Rate, counter, days_to_christmas, TheNameIsSoLongThatYouWillMakeMistakesWithIt, _.
Moreover, Python lets you use not only Latin letters but also characters specific to languages that use other alphabets.
These variable names are also correct:
Adiós_Señora, sûr_la_mer, Einbahnstraße, переменная.
And now for some incorrect names:
10t (does not begin with a letter), Exchange Rate (contains a space)
NOTE:
The PEP 8 -- Style Guide for Python Code recommends the following naming convention for variables and function in Python:
variable names should be lowercase, with words separated by underscores to improve readability (e.g., var, my_variable)
function names follow the same convention as variable names (e.g., fun, my_function)
it's also possible to use mixed case (e.g., myVariable), but only in contexts where that's already the prevailing style, to retain backwards compatibility with the adopted convention.
Keywords
Take a look at the list of words that play a very special role in every Python program.
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
They are called keywords or (more precisely) reserved keywords. They are reserved because you mustn't use them as names: neither for your variables, nor functions, nor any other named entities you want to create.
The meaning of the reserved word is predefined, and mustn't be changed in any way.
Fortunately, due to the fact that Python is case-sensitive, you can modify any of these words by changing the case of any letter, thus creating a new word, which is not reserved anymore.
For example - You can't name your variable like this:
import
You mustn't have variable named in such a way - it is prohibited. But you can do this instead:
Import
These words might be a mystery to you now, but you'll soon learn the meaning of them.