Python Constructors and Methods, object-oriented programming - Python programming for beginners. In this video I teach the basics of object-oriented programming and how to get started in building your first class.
Code for tutorial: -
---------------------------------------------------------------------------
class Car:
def __init__(self,name,speed):
self.name = name
self.speed = speed
def acceleration(self):
self.speed += 5
def brake(self):
self.speed -= 5
def display_car(self):
print(f"The cars name is {self.name}")
print(f"The cars speed is {self.speed}")
from car import Car
car1 = Car()
# print(car1)
# car1.name = "blue"
car1.speed = 100
# print(car1.speed)
print(car1.name)
car2 = Car("red", 200)
print(car2.speed)
print(car2.name)
car2.acceleration()
car2.acceleration()
print(car2.speed)
car2.brake()
print(car2.speed)
car2.display_car()
On this page of the site you can watch the video online Python Constructors and Methods, object-oriented programming - Python programming for beginners. with a duration of hours minute second in good quality, which was uploaded by the user Brendan Callaghan 17 November 2022, share the link with friends and acquaintances, this video has already been watched 120 times on youtube and it was liked by 3 viewers. Enjoy your viewing!