-
Book Overview & Buying
-
Table Of Contents
Python Illustrated
By :
There are a few rules for naming your variables. We have two types of rules: we have Python rules and conventions. The Python rules are non-negotiable; if you break these, your code won’t work. The conventions are good practices; however, if you break them, your code will still work.
Let’s start with the Python rules. Variables must start with a letter or an underscore. They can’t start with a number. The rest of the variable name can have letters, numbers, and underscores. It’s important to keep in mind that variable names are case-sensitive. That means that you need to refer to a variable with the exact same casing as you chose at first.
Here are some examples of valid variable names (not all of them follow best practices!):
result = 12
Result = 12
_result = 12
result1 = 12
result_1 = 12
result_ONE_1 = 12
And here are some examples of invalid variable names:
1result
#result
?result
The good practices in Python...