Python Constructors and Methods, object-oriented programming - Python programming for beginners.

Publicado em: 17 Novembro 2022
no canal de: Brendan Callaghan
120
3

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()


Nesta página do site você pode assistir ao vídeo on-line Python Constructors and Methods, object-oriented programming - Python programming for beginners. duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Brendan Callaghan 17 Novembro 2022, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 120 vezes e gostou 3 espectadores. Boa visualização!