Horje
difference between object and class in python Code Example
difference between object and class in python
# In Object Oriented Programming (OOP):
# An object is an instance of a class.
# A class is a blueprint/template for an object.

# A class is a collection of attributes (data/variables) and methods (functions) 
# which fulfill a specific function.

# Example: 

class Car():
    def __init__(self, brand, model, colour, owner):
        self.brand = brand
        self.model = model
        self.colour = colour
        self.owner = owner
            
    def honk(self):
        print(f"I am {self.owner}'s {self.colour} {self.brand} {self.model}!")
        
bob_car = Car('Volvo', 'Sedan', 'black', 'Bob') 
amy_car = Car('Mini', 'Cooper', 'red', 'Amy')

bob_car.honk()
amy_car.honk()

# >>> I am Bob's black Volvo Sedan!
# >>> I am Amy's red Mini Cooper!

# Car is the blueprint for the objects bob_car and amy_car.
# bob_car and amy_car objects were instantiated from the class Car.




Python

Related
Which function is used to write all the characters? Code Example Which function is used to write all the characters? Code Example
modwt python github code Code Example modwt python github code Code Example
<function chr(i, /)> error in python Code Example <function chr(i, /)> error in python Code Example
Check if file already existing Code Example Check if file already existing Code Example
sum function python Code Example sum function python Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7