- naming styles for identifiers like - variables, constants, functions, classes
- naming doesnt affect the functionality - it just improoves the readability
- single lowercase letter
- loop variables -
i
andj
- loop variables -
- single uppercase letter
- full lowercase name
- lowercase with underscore
name_var_three
(snake case) - full uppercase
- typically used with constants
- full uppercase with underscores
- capitalized words
VarThree
(camel case - pascal case)- typically used with classes
- upper camel case
VarThree
- lower camel case
camelCase
- capitalized words with underscores
Var_Three_Four
- a variable name must start with a letter or underscore
- a variable name cannot start with a number
- variable names can only contain alphanumeric characters and underscores
- variable names are case sensitive
- variables cannot contain spaces
- variables should be written in lowercase with words seperated by underscores
variable_one
...snake_case
(same with function names)
- choose meaningful names
- dont use variable names that dont represent thier actual value
- a variable named
clients_list
should not be a tuple
- a variable named
- variables should be meaningful and distinct
- variable named should be pronounceable ....
player_score
is better thanplr_score
- dont use lowercase
l
as a single character variable (larry) - dont use uppercase
O
as a single character variable (oliver)
- keywords are reserved words that cannot be used as variable names, function names or any other identifier
- to see the python keywords in the interactive shell....
help()
thenkeywords
- if you need to use one of the keywords you can add a single trailing underscore...
list_
....class_
- a constant is a value that cannot change during the execution of the program
- constants are usually written on a module level and are written in all capital letters with underscores seperating words....
MAX_OVERFLOW
orTOTAL
CONSTANT_NAME
- In Python you cant actually create constants that cant change, but you can recognize the naming convention and not change thier values
- boolean variables should typically start with
is
orhas
- EX:
is_valid
orhas_pets
orhas_children
oris_logged_in