Untitled Deck Flashcards
(50 cards)
snake_case is used for
variables and functions
core types
can be checked with method type()
extend()
can concatenate two lists;
list1.extend(list2)
identity operators
check for types;
is / is not
dictionaries
unordered and mutable
tuples
ordered but immutable, allowing duplicates. Should be used for values that will not change.
count()
count occurrences of something;
item.count(x)
index()
returns position of the first instance of that value;
item.index(x)
floor division
rounds down if the result is a decimal
list comprehensions
listname = [(process) for x in range(y)];
outputs the result of the process over the range
list slicing
list[starting index, ending index + 1];
excludes last number
dictionary access / assignment
my_dict[‘key’] = value
continue
continue skips the current iteration and moves to the next if condition is/n’t met
break
exits the loop if the condition is/n’t met with no more iterations
class
a definition for a variable to act a certain way and comply with new functions
object
an instance of a class, following the rules of that class with unique data;
object = myClass(a1, a2…)
__init__
a constructor; automatically called when an object of a class is created.
initializes (confirms + stores) the unique attributes
inheritance
a subclass inherits properties and methods from an existing class; promotes code reuse;
class Animal: …
class Dog(Animal): …
both have function speak(self)
super()
within a subclass, super() calls methods from the superclass without adding them to the subclass.
often used in the __init__ method for the subclass to initialize attributes inherited from the superclass
encapsulation
the bundling of attributes and methods into a single unit and restricting direct access to come of the object’s components;
coupling attributes into a class to protect the integrity of the data
polymorphism
the ability of an object to take on many forms;
methods can be overwritten in subclasses with super().func()
refactor
third step of TDD: clean up code after ensuring the tests pass
atomic operations
performed as a single, uninterruptible step;
arithmetic, variable assignment, branching statements.jumps,
all dictionary operations are
of O(1) time complexity