Naming convention
Lesson 16 of 28 in Coddy's Clean Code - Write better code using Python course.
PEP 8 follows the suggested Python naming convention as we saw before :
| Type | Convention | Example |
|---|---|---|
| Variable | snake_case all lower case | generated_result |
| Function | snake_case all lower case | print_info() |
| Constant | snake_case all upper case | PI = 3.14 |
| Class | CamelCase | MyClass |
| module | snake_case all lower case | numpy |
Challenge
EasyYou are given with some PEP 8 naming conventions violations can you spot & fix them?
Try it yourself
class soul:
free_string = 'Soul freed' # const string
def __init__(self, NAME):
self.NAME = NAME
def Free(self):
print(self.free_string + ' - ' + self.NAME)
if __name__ == '__main__':
instance = soul('John Doe')
instance.Free()