Naming Styles

The table below outlines some of the common naming styles in Python code and when you should use them:

TYPE…. …. NAMING CONVENTION EXAMPLES
Function Use a lowercase word or words. Separate words by underscores. function, my_function
Variable
Use a lowercase word or words. Separate words by underscores.
x, var, my_variable
Class Start each word with a capital letter. Do not separate words with underscores. (camel case) Model, MyClass
Method
Use a lowercase word or words. Separate words by underscores.
class_method, method
Constant

Use an uppercase single letter, word, or words. Separate words with underscores.
CONSTANT, MY_CONSTANT, MY_LONG_CONSTANT
Module
Use a lowercase word or words. Separate words by underscores.
module.py, my_module.py
Package
Use a lowercase word or words. Do not Separate words by underscores.
package, mypackage


Full stack Java Developer

   Buy me a coffee!

 

PayTM QR (INDIA)

Download file

Leave a Reply

avatar
  Subscribe  
Notify of
Close Menu