Be Globally Certified In Python
Python is a great text coding programming language for kids!
Rules for Naming Variables:
1. Variable names must begin with a letter (a-z, A-Z) or an underscore (_).
-
- Correct:
my_var
,_data
,Name
- Incorrect:
123abc
,@value
,1stPlace
- Correct:
- Variable names can contain letters, numbers, and underscores.
- Correct:
my_var_123
,data_value
,Name2
- Incorrect:
my-var
,data@value
,my variable
- Correct:
- Variable names are case-sensitive.
- Correct:
count
,Count
, andCOUNT
are treated as different variables. - Incorrect:
count
andCount
are the same variable.
- Correct:
- Variable names should not be the same as Python keywords or reserved words (e.g.,
if
,else
,for
,while
,import
,def
, etc.).- Correct:
my_var
,value_1
- Incorrect:
if
,import
,class
, etc.
- Correct:
- Variable names should be descriptive and meaningful to improve code readability.
- Correct:
total_count
,user_input
,student_age
- Incorrect:
x
,temp
,var
- Correct:
- Conventionally, variable names should use lowercase letters and underscores for readability (snake_case).
- Correct:
user_age
,data_value
- Incorrect:
userAge
,DataValue
- Correct:
- Avoid using single-letter variable names unless for temporary or loop variables.
- Correct (for temporary or loop variables):
i
,j
,temp
- Incorrect (for general variables):
x
,y
,a
- Correct (for temporary or loop variables):