Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python naming conventions

#module names should be all lowercase
import mymodule
#normal variables are lowercase_with_underscores
my_variable = 'value'
#constants are UPPERCASE
CONSTANT = 'never changes'
#classes are UpperCaseCamelCase
class MyClass(self):
    pass
Comment

python naming conventions

################################################################################
#IN COMMENTS
################################################################################

# module/file names should be in lowercase (ALL LETTERS)
# example: import mymodule OR import myfile

# ------------------------------------------------------------------------------

# variable/parameter names should use snake case

# (means separate words by '_' (underscore))
# example: this_is_a_variable: int = 5 (: int, represents data type)
# example 2: this_is_a_parameter: str = 'A String'

# ------------------------------------------------------------------------------

# functions: same as variables and parameters

# ------------------------------------------------------------------------------

# classes, uses CamelCase, First letter of each word should be Capital
# example:
# class AClassOk:
#	def __init__(self):
#		pass

# ------------------------------------------------------------------------------

# Constants: ALL LETTERS SHOULD BE CAPITAL, WORDS SEPERATED BY '_'(UNDERSCORE).
# CONST = "OOF"

###############################################################################
# IN REAL LIFE
###############################################################################

import amodule

a_var: float = 3.1

def eat_burger(a_parameter):
  print(a_parameter)
  
class EatCocaCola:
  def __init__(self):
    pass

A_CONST: bool = False
  
Comment

Python naming conventions

Packages: short, all-lowercase names. Preferably no underscores.=>utilities

Modules: short, all-lowercase names. Can have underscores.	=> db_utils

Classes: CapWords (upper camel case) convention 			=> BankAccount

Functions: lowercase, words separated by underscores  		=> open_account
(snake_case)

Variables: lowercase, words separated by underscores 		=> account_id
(snake_case)

Constants: all-uppercase, words separated by underscores	=> MIN_APR
Comment

PREVIOUS NEXT
Code Example
Python :: python how to get the screen size 
Python :: how to detect language python 
Python :: jupyter notebook add color text 
Python :: add custom field to serializer 
Python :: how to remove stop words in python 
Python :: max pooling tf keras 
Python :: unique id python 
Python :: python xml parser 
Python :: Simple way to measure cell execution time in ipython notebook 
Python :: how to write to the end of a file in python 
Python :: upgrade python wsl 
Python :: remove 1st column pandas 
Python :: stock market api python 
Python :: how to convert gb to mb in python 
Python :: python string to list with separator 
Python :: pandas merge on columns different names 
Python :: python pyramid 
Python :: float to percentage python 
Python :: python raise and exit 
Python :: create close python program in puthon 
Python :: python remove empty list 
Python :: assignment 7.1 python data structures 
Python :: numpy array_equal 
Python :: count the number of rows in a database table in Django 
Python :: Python Tkinter Canvas Widget 
Python :: plotly hide color bar 
Python :: replace all nan values in dataframe 
Python :: python difflib compare two strings 
Python :: python append a file and read 
Python :: python how to check if first character in string is number 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =