Classes and Objects
Classes:
class Vehicle:
passclass Vehicle:
def __init__(self, body_type, make):
vehicle_body = body_type
vehicle_make = make
# Initiallizing the class:
car1 = Vehicle("jeep", "toyota")
print(car1.vehicle_body)class Vehicle:
def __init__(self, body_type, make):
self.vehicle_body = body_type # Using self
self.vehicle_make = make # To reference itself
# For other objects
# Initiallizing the class:
car1 = Vehicle("jeep", "toyota")
car2 = Vehicle("truck", "mercedes")
# Prints jeep
print(car1.vehicle_body)
# prints mercedes
print(car2.vehicle_body)PreviousRevising the Difference between Methods and FunctionsNextClasses Attributes vs Object Attributes
Last updated