Variable Names
When naming variables in Python, there are a few rules and best practices you should follow:
- Must start with a letter or an underscore: Variable names cannot begin with a number. For example,
_var
andvar
are valid, but1var
is not. - Can contain letters, numbers, and underscores: You can use alphanumeric characters and underscores, such as
var_1
. - Case-sensitive: Python variables are case-sensitive, so
Var
andvar
would be two different variables. - No spaces: Variable names cannot contain spaces. Instead, use underscores, like
my_variable
.
Example of valid variable names:
Python
my_variable = 10
_variable = "Python"
Var123 = [1, 2, 3]
Import Links
Here are some useful import links for further reading: