Indexing and range (starting from 0 by default)
○ [start (inclusive) : end (exclusive) : stepsize (optional)] = [0, 1, 2, 3] = [-4, -3, -2, -1]. Tip: end - start is the number of elements returned
○ Range(start (inclusive), stop (exclusive), stepsize). Range(3): 0, 1, 2. The start, stop and step parameters work the same as in list slicing.
○ Set function is used to create a set, particularly useful for removing duplicates from a list or character returns as { }.
Slicing (for lists, strings and tuples)
○ To copy a list in Python and ensure that changes to the new list do not affect the original list, you can use the list( ) or copy( ) functions, or
create a copy of a list by slicing it from the beginning to the end x[ : ] or x[ : : ]. Do not use the equal to sign to copy lists.
○ With positive steps you go from the start index to the right, with negative steps you go from the end to the left.
○ [ : : -1] reverses the list. [ : index] starts from index zero. [index : ] ends at, including the last element.
Importing packages – import package (as nickname). If you want to make your import more selective use – from package import function.
Functions
○ A function in Python is an object that encapsulates executable code, which can
be invoked by its name. Functions are defined with parameters in their headers,
and when called, arguments are passed to these parameters.
○ It may return a value using a return statement; if no return statement is
executed, None is returned by default.
○ Python fills any explicitly defined parameters first with the provided arguments.
○ [start (inclusive) : end (exclusive) : stepsize (optional)] = [0, 1, 2, 3] = [-4, -3, -2, -1]. Tip: end - start is the number of elements returned
○ Range(start (inclusive), stop (exclusive), stepsize). Range(3): 0, 1, 2. The start, stop and step parameters work the same as in list slicing.
○ Set function is used to create a set, particularly useful for removing duplicates from a list or character returns as { }.
Slicing (for lists, strings and tuples)
○ To copy a list in Python and ensure that changes to the new list do not affect the original list, you can use the list( ) or copy( ) functions, or
create a copy of a list by slicing it from the beginning to the end x[ : ] or x[ : : ]. Do not use the equal to sign to copy lists.
○ With positive steps you go from the start index to the right, with negative steps you go from the end to the left.
○ [ : : -1] reverses the list. [ : index] starts from index zero. [index : ] ends at, including the last element.
Importing packages – import package (as nickname). If you want to make your import more selective use – from package import function.
Functions
○ A function in Python is an object that encapsulates executable code, which can
be invoked by its name. Functions are defined with parameters in their headers,
and when called, arguments are passed to these parameters.
○ It may return a value using a return statement; if no return statement is
executed, None is returned by default.
○ Python fills any explicitly defined parameters first with the provided arguments.