Menu
Coddy logo textTech

Naming Conventions

Lesson 3 of 28 in Coddy's Clean Code - Write better code using Python course.

Naming is crucial part of writing code, You give names to variable, function, classes and more...

Python introduce some suggested naming styles:

TypeConventionExample
VariableSnake casex, index, max_number
FunctionSnake casecalculate, convert_to_int
ClassPascal casePerson, JavaCompiler
MethodSnake caseprint, make_sound
ConstantSnake case (all caps)PI, MAX_TIMEOUT, MIN_AGE
ModuleSnake casescript.py, my_app.py
PackageSnake case (without underscores)package, mypackage
  • Snake case (snake_case) - Lower case letters, words separated with underscores.
  • Pascal case (PascalCase) - Capitalised words

More detailed example of using it all together,

import my_module


class ImportantClass:
	MY_CONSTANT = 3.14
	def good_function(self, variable):
		return variable
		
	def better_function(self):
		return MY_CONSTANT
		

def __name__ == '__main__':
	var = my_module.secret()
	important_class = ImportantClass()
	important_class.good_function(var)
	print(important_class.better_function())

Notice all the diferent types here!

Did you know? the difference between function and method is that method is a function associated with object/class

Try it yourself

This lesson doesn't include a code challenge.

All lessons in Clean Code - Write better code using Python