conventions¶
The following are a few conventions to know in Python
names¶
class names are usually in
CamelCase
for exampleclass AClassName(object):
I can use any case I want but TitleCase keeps things consistent
variables (attributes) and function (method) names are in
snake_case
for exampledef function_name(argument_1, argument_2, 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'
"""Multiline Text
with
triple double quotes
"""
'''Multiline Text
with
triple single quotes
'''
tuples¶
A tuple is a sequence or container of objects that cannot be changed later, it is immutable 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 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, 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
{
'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
# This is a comment