03 Three
03 Three
our
own
Classes
Think of a Class as a Blueprint
A Class:
Is a Blueprint/Template for creating objects
Class Object
instance = Class()
Object A class is always
Capitalized and followed
by parentheses
An Object is a Variable
equal to a Class Remember -> t1 = Turtle()
Object Class
Examples of Objects:
They are All Animals sharing some of the same properties. They
all have additional properties and actions of their own
Animals
Telephone
An Object
Animals A Class (Family)
Constructor
Construction
Used to Build
The Constructor Function:
It's a method (function) that is automatically ran when an
object is created. It creates an instance of a specific class
Constructor
__init__()
self -> Is basically a "key". It unlocks the Calling/Using the drive method we built in the class
car.drive()
Looking at another Class:
class App():
def __init__(self, users, storage, username):
self.users = users
self.storage = storage product_one = App(35, 256, "owner")
product_one.login()
self.username = username
product_one.increase_capacity(50)
def login(self):
if self.username == "owner" and self.users >= 1: product_two = App(35, 128, "josh")
print("Welcome,", self.username) product_two.login()
if name != "done" or name != "quit": count = int(input("Enter count: ")) ages = [33, 25, 62, 15, 19, 33]
print("Hello,", name)
elif name == "josh": while count != 0: for age in ages:
print("It's me Josh") if count >= 10: if age <= 17:
else: count -= 2 ages.remove(age)
print("Removed, under 18")
print("Goodbye") else:
else:
count -= 1
print("Person Age:", age)
print("Current count:", count) ages.sort()
count = int(input("Enter count: print("Ages list:", ages)
"))
Challenge #1 in VS code:
DO NOT GO BACK!