conventions
The following are a few conventions to know in Python
CapWords
Class names in Python are written in the CapWords format, where the first letter of every word in the name is capitalized
names
class names are usually in CapWords for example
class AClassName(object):I can use any case I want but CapWords keeps things consistent
variables and function/method names are in
snake_casefor exampledef function_name(first_input, second_input, keyword_argument=None): ... variable_name = None
for more details see the Python Style Guide
enclosures
Enclosures must be closed once open, which means they happen in pairs for example
""
""""""
''
''''''
()
[]
{}
The Integrated Development Environment (IDE) takes care of this
quotes
Quotes represent strings and can be single, double, triple single or triple double for example
"Double Quotes"
'Single Quotes'
"""Text on different lines
with
triple double quotes
"""
'''Text on different lines
with
triple double quotes
'''
tuples
A tuple is a sequence or container of objects that cannot be changed later, it is immutable (cannot be changed later) and represented with parentheses/brackets (()), for example
(1, 2.5, "three", [4, 'five'])
lists
A list/array is a sequence or container of objects that can be changed after it is defined, it is mutable (can change later) and represented with square brackets ([]), for example
[1, 2.5, 'three', (4, "five")]
sets
A set is a container of objects that have no duplicates, and are represented with curly braces/brackets ({})
{1, 2.5, 'three', (4, 'five')}
dictionaries/mappings
Dictionaries/Mappings are also represented with curly braces/brackets ({}) but have key-value pairs, for example
{
'integer': 1,
'floating_point': 2.5,
'string': 'three',
'tuple': (1, 2.5, "three", [4, 'five'])
'list': [1, 2.5, 'three', (4, "five")]
'set': {1, 2.5, 'three', (4, 'five')}
}
comments
Comments are represented by the hashtag or pound before the thing that is commented for example