0
0
Pythonprogramming~5 mins

Naming rules and conventions in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What characters can you use to start a variable name in Python?
A variable name must start with a letter (a-z, A-Z) or an underscore (_). It cannot start with a number or special character.
Click to reveal answer
beginner
Is the variable name my-variable valid in Python? Why or why not?
No, because the hyphen (-) is not allowed in variable names. Use underscores (_) instead, like my_variable.
Click to reveal answer
beginner
What is the naming convention for constants in Python?
Constants are usually written in all uppercase letters with underscores separating words, like MAX_SPEED.
Click to reveal answer
beginner
How should you name a function in Python according to conventions?
Function names should be lowercase with words separated by underscores, like calculate_total.
Click to reveal answer
beginner
Why should you avoid using Python reserved keywords as variable names?
Reserved keywords have special meaning in Python and using them as variable names will cause errors or unexpected behavior.
Click to reveal answer
Which of these is a valid Python variable name?
Auser-name
Buser_name
C2ndUser
Duser name
What is the correct way to name a constant in Python?
AMAX_SPEED
BmaxSpeed
Cmax_speed
DMaxSpeed
Which of these is NOT allowed as a variable name in Python?
Aclass
B_temp
Ctotal1
Dvalue_2
How should function names be written in Python?
ACalculateTotal
Bcalculate-total
Ccalculate_total
DcalculateTotal
Which character is NOT allowed in Python variable names?
Aa
B9
C_
D-
Explain the basic rules for naming variables in Python.
Think about what characters are allowed and what is not.
You got /4 concepts.
    Describe the common naming conventions for constants and functions in Python.
    Consider how uppercase and lowercase letters are used.
    You got /3 concepts.