Naming Convention for Variables #
The naming convention for variables may differ in each programming language. In Python, variables can have English letters, both lowercase and uppercase a-z A-Z, numbers 0-9, and underscores _. However, variable names cannot start with a number. Examples of valid variable names are:
age = 1
Age = 2
aGe = 3
AGE = 4
a_g_e = 5
_age = 6
age_ = 7
_AGE_ = 8
Examples of invalid variable name:
1099_failed = False
- Snake Case, which uses an underscore _ between words, such as student_name, company_phone_number
- Kebab Case, which is similar to Snake Case but uses a hyphen - instead of an underscore _, such as student-name, company-phone-number
- Camel Case, which uses the first letter of each word capitalized, except for the first word, such as studentName, companyPhoneNumber
- Pascal Case, which is similar to Camel Case but starts with a capitalized first letter for the first word, such as StudentName, CompanyPhoneNumber
In Python, snake case is a convention used for naming variables.
Exercise #
- Change the variable name from
1099_failedtoyear.
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules