Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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
  
 
PREVIOUS NEXT
Tagged: #python #naming #conventions
ADD COMMENT
Topic
Name
9+6 =