Python objects as arguments 🏍️

preview_player
Показать описание
Python pass objects as arguments tutorial example explained

#python #objects #arguments

class Car:

color = None

class Motorcycle:

color = None

def change_color(vehicle,color):

car_1 = Car()
car_2 = Car()
car_3 = Car()

bike_1 = Motorcycle()

change_color(car_1,"red")
change_color(car_2,"white")
change_color(car_3,"blue")
change_color(bike_1,"black")

Bro Code merch store 👟 :
===========================================================
===========================================================
Рекомендации по теме
Комментарии
Автор

class Car:

color = None

class Motorcycle:

color = None

def change_color(vehicle, color):

vehicle.color = color


car_1 = Car()
car_2 = Car()
car_3 = Car()

bike_1 = Motorcycle()

change_color(car_1, "red")
change_color(car_2, "white")
change_color(car_3, "blue")
change_color(bike_1, "black")

print(car_1.color)
print(car_2.color)
print(car_3.color)
print(bike_1.color)

BroCodez
Автор

I'm sitting
I'm relaxing
And I'm really enjoying the show
Thanks bro

The-Martian
Автор

keep uploading. such a great effort and quality

manuelvaal
Автор

Hello nice vid but i would like ask you the following question, how python knows that we pass a car object without declare it and also we can have access to its attributes? inside the function

Testertester-jklg
Автор

I don't understand how you came up with the variable "car.color" under function "change_color()" since I know both "car" and "color" are seperate parameters for function "change_color".

don_d
Автор

if im honest, this is the first thing i cant get my head around . I understand why it works, i just cant explain how or why. thnaks tho L:

lmthed
Автор

Looking for it since ages xd finally got it

allamsrikanth