4. Python - Naming Conventions
4. Python - Naming Conventions
Table of Contents
1. Identifier........................................................................................................ 2
2. Why should we follow naming conventions? ............................................... 2
3. Points to follow for identifiers in Python ...................................................... 3
# Point 1 ......................................................................................................... 3
# Point 2 ......................................................................................................... 4
# Point 3 ......................................................................................................... 5
# Point 4 ......................................................................................................... 6
# Point 5 ......................................................................................................... 6
Examples......................................................................................................... 7
Common error ................................................................................................... 7
4. Python identifiers table ................................................................................. 8
5. Comments in program................................................................................. 10
Purpose of comments ................................................................................... 10
1. Singe line comments ................................................................................. 10
2. Multi line comments ................................................................................. 11
1. Identifier
o Package name
o Module name
o Variable name
o Function name
o Class name
o Method name
✓ While writing the program if we follow the naming conventions then the
written code is,
o Easy to understand.
o Easy to read.
o Easy to debug.
# Point 1
✓ If we are using any other symbol then we will get syntax error.
student_id = 101
print(student_id)
Output
101
$tudent_id = 101
print($tudent_id)
Error
# Point 2
✓ We can write an identifier with number but identifier should not start
with digit.
student_id123 = 101
print(student_id123)
Output
101
123tudent_id = 101
print(123tudent_id)
Error
SyntaxError: invalid decimal literal
# Point 3
value = 10
print(value)
Error
10
value = 10
print(VALUE)
Error
NameError: name 'VALUE' is not defined
# Point 4
if = 10
print(if)
Error
SyntaxError: invalid syntax
# Point 5
student id = 101
print(student id)
Error
SyntaxError: invalid syntax
Examples
✓ 435student # invalid
✓ student564 # valid
✓ student565info # valid
✓ $tudent # invalid
✓ _student_info # valid
✓ class # invalid
✓ def # invalid
Common error
o Example: StudentInfo
2. package
6. method
o Example: _balance
o Example: IN_PROGRESS
o Example: __init__(self)
5. Comments in program
Purpose of comments
output
Welcome to python programming
10 | P a g e 4.PYTHON-NAMING CONVENTIONS
Data Science – Python Naming Conventions
"""Author Daniel
Project Python project
Location Bengaluru"""
output
Welcome to python programming
11 | P a g e 4.PYTHON-NAMING CONVENTIONS