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

Pubblicato il: 17 novembre 2022
sul canale di: 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()


In questa pagina del sito puoi guardare il video online Python Constructors and Methods, object-oriented programming - Python programming for beginners. della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Brendan Callaghan 17 novembre 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 120 volte e gli è piaciuto 3 spettatori. Buona visione!