Module 8: Classes Flashcards
A class has ______ which are variables of the class and _______ which are functions to be called on instances of the class.
attributes
methods
The annotation of an attribute says _______ ________ ______
name
colon
type
Documentation for a class includes ________ and __________.
docstring
attribute annotations
______ methods start and end with two underscores, for the user to be able to use without defining them.
magic
__________ is used to give a more meaningful initialization of an object.
__init__
_________ and ________ are used to give a description of a printed object.
__repr__
__str__
_________ is used to redefine the comparison operator.
__eq__
a ________ is a function that is part of a class and will be called on an object.
method
All class methods must begin with _______ referential parameter which allows you to refer to the object that called this method.
self
Self is a value of _______ type as class being defined, so ______ the type annotation.
same
omit
While defining a class the class is not yet defined so _________ use the __________ inside the class definition. Instead, when referring to a value of the same class, use a ________ containing the name of the class.
cannot
name of the class
string
Instances of a class are _________.
objects
__init__ returns _________. ______ the annotation.
None
omit
Classes are ______ and can be _________ like dictionaries.
mutable
aliased
When using a class object, access the attributes and methods of the class by calling the __________ followed by _________ or __________.
object name
.attribute
.method(parameters)
Use ____________ to display whatever information of interest from a class. Typically used to display all attribute values of the class and tell the user which value is which.
__repr__
To create a brand new object and copy all the attributes of another object use the format: _______________________
india_copy = Country(india.continent, india.leader, india.population)
To alias an object use the format: ________________.
india_alias = india
The default for how == is defined is _________. Often this is changed by overriding the __________ magic method. Now need to use ________ to determine if 2 objects are aliases of each other.
aliasing
__eq__
is
With overriding __________ method the equality can be utilized for two values of _______ type. Use method ______________ to check whether the type of object_name is equal to class_name.
__eq__
any
isinstance(object_name, class_name)
An object is ________ the same as its representation.
not