This word represents the characteristics or properties of an object.
attribute
_______ Bicycle():
def __init__(self, myMake):
self.make = myMake
class
class Soda():
def __init__(self, myBrand, myFlavor, myPrice):
self.brand = myBrand
self.flavor= myFlavor
self.price= myPrice
soda1 = Soda()
When making the object, it needs arguments.
ex.: soda1 = Soda("Coke", "Cherry", 2.99)
What is the first parameter of all methods?
self
What is the function used to call a parent class?
super()
A code template or "blueprint" used to create objects.
class
class Person():
def __init__(self, myName, myAge):
self.name= myName
self.age = myAge
dude = ________("Joey", 13)
Person
class Pet():
def __init__(self, mySpecies, myName):
self.species = mySpecies
self.name = myName
def printInfo(self):
print("Species:", self.species)
print("Name:", self.name)
fido = Pet("dog", "Fido")
print(fido)
You don't want to print an object directly. Instead, use the printInfo() method:
fido.printInfo()
__init__
A _________ class is more general, while a ________ class is more specific.
parent; child
One specific instance of a class.
Object
class Vehicle():
def __init__(self, myColor, myModel):
_______.color = myColor
_______.model = myModel
self
class Player():
def __init__(self, myX, myY):
self.x= myX
self.y= myY
self.score= 0
player1 = Player(100, 200, 0)
A player is constructed with only the x and y as attributes; the points do not need to be specified as that is already done inside the body of the constructor. Should be:
player1 = Player(100, 200)
A method is a __________ that is placed inside a _________.
function; class
What happens if a method is defined in the parent class but not in the child class?
The child class inherits the method automatically without any changes.
This word describes the ability of one class to acquire all the attributes and methods of another class.
Inheritance
Write a method, called ageUp that increases an attribute called age by 1.
def ageUp(self):
self.age += 1
What is it called when a child class executes its own version of a method rather than the one in the parent class.
Overriding a method
What do we call the period in between an object and an attribute or method, such as:
class Animal():
def __init__(self, myName):
self.name = myName
def growl(self):
print("Grrr.... says", myName)
______________ #creates an Animal named Fido
______________ #makes Fido growl
fido = Animal("Fido")
fido.growl()
class Animal():
def __init__(self, myName):
self.name = myName
class Cat():
def __init__(self, myName, myBreed):
super().__init__(myName)
self.breed = myBreed
The parent class is never indicated. Should be:
class Cat(Animal):
Write a constructor to be placed in a Coin class. The Coin should have three attributes (x, y, and points). A Coin can start at any (x, y) position, but should ALWAYS start with 5 points when created.
def __init__(self, myX, myY):
self.x = myX
self.y = myY
self.points = 0
What is the purpose of inheritance?
To allow child classes to reuse, extend, or customize functionality from a parent class without rewriting code.