Working With Variables – Python Programming
The last variable we used, we called it age. There were no problems with the program and it ran well. However, there are certain rules when naming variables. You cannot just name variables whatever you want. Different languages have different rules regarding the naming of variables, But we will strictly look at the rules from python.
- Should begin with uppercase or lowercase alphabets (a – z, A – B) or and underscore ( _ ). 1_age is not allowed whereas age_1 is allowed.
- Preceding characters can contain alphabets, underscores, and numbers as well.
- Variables are strictly case-sensitive. Age is different from age.
- Reserved keywords themselves cannot be used, however, you can use them within a full variable name.A variable named if is not allowed but a variable named x_if if absolutely fine.
Here is a list of keywords in python.