Week 5 Flashcards
What are the components of an objects?
- State
- Method
Where is the state stored?
The state of an object is stored in instance variables
What is a state of an object?
These are the attributes that define an object.
What are the methods of an objects?
These are the actions that an object can perform.
How do you define a class with name X?
class X: """ X class for representing X states and has X methods"""
What method should every class have?
__init__
What is the initializer method/constructor? Wjhat is its role?
A method that is automactically called when a new instance of a given class is called.
It allows programmers to set up attributes within the new instance by giving them initial values.
What is the syntax for the constructor?
def \_\_init\_\_(self): self.X = x
NOTE:
X = name of attribute
x = initial value of attribute
What is the convention when referring to the object in the initializer?
The self parameter is the convention.
NOTE: Technically can be anything though
What is the name of a function that creates a new object instance?
A constructor
What is the name of the combined process of initializing a new object and setting its initial values?
Instantiation
What are magic methods?
What does self. refer to?
Refers to the object being instantiated