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
I think python doesn't know that you're passing a car object. Whatever object that you pass in as an argument, it will try to access the color attribute whether it has that attribute or not. If it has a color attribute, then it's all good. If not, then it will produce an error. Correct me if I'm wrong tho.
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".
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)
I'm sitting
I'm relaxing
And I'm really enjoying the show
Thanks bro
keep uploading. such a great effort and quality
Great,,,,,
Great
Thanks
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
this is how it works bro, that`s why we are learning it.
I think python doesn't know that you're passing a car object. Whatever object that you pass in as an argument, it will try to access the color attribute whether it has that attribute or not. If it has a color attribute, then it's all good. If not, then it will produce an error.
Correct me if I'm wrong tho.
@@vincehernandez2469 exactly, so it may be a good idea to do some error handling on that
nice
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".
Ty bro
Thanks bro
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:
same tbh
Wow!
thanks
nice tutorial :)
cool, Bro
Thanks!
Cool
thx 4 vid bro !
Gooo
Thanks Bro!
❤
Thank you Bro!
Is color not a class variable ?
thaaaaaaaaaaank you!!
Looking for it since ages xd finally got it
love u
My two cents!
Thanks bro
Thanks Bro!