Answers for "python naming conventions"

13

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
Posted by: Guest on March-26-2020
1

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
Posted by: Guest on August-27-2021
0

python naming script

# Function gets name from user
def get_name():
    print("Hello what is your name?")
    name = input("My name is: ")
    print("Hello ", name)
    return name
Posted by: Guest on June-30-2020
0

class name convention python

# PEP 8 Class names
# Class names should normally use the CapWords convention.

class MyClass:
  def __init__(self):
    # Variable and method names are snake_case
    self.load_time = 25
  def print_value(self, value):
    print(value)
Posted by: Guest on December-23-2020

Python Answers by Framework

Browse Popular Code Answers by Language