Python objects as arguments 🏍️

Поділитися
Вставка
  • Опубліковано 23 жов 2024

КОМЕНТАРІ • 35

  • @BroCodez
    @BroCodez  3 роки тому +13

    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)

  • @The-Martian73
    @The-Martian73 Рік тому +10

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

  • @manuelvaal1257
    @manuelvaal1257 2 роки тому +3

    keep uploading. such a great effort and quality

  • @dineshgautam7027
    @dineshgautam7027 2 роки тому +1

    Great,,,,,

  • @zharfa1357
    @zharfa1357 2 роки тому +1

    Great

  • @rubenc4696
    @rubenc4696 6 місяців тому

    Thanks

  • @Testertester-jk3lg
    @Testertester-jk3lg 3 роки тому +3

    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

    • @supersonusourav
      @supersonusourav 3 роки тому +2

      this is how it works bro, that`s why we are learning it.

    • @vincehernandez2469
      @vincehernandez2469 3 роки тому +7

      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.

    • @huntercraft5674
      @huntercraft5674 Рік тому +1

      @@vincehernandez2469 exactly, so it may be a good idea to do some error handling on that

  • @uuhju7004
    @uuhju7004 3 роки тому +1

    nice

  • @don_d1997
    @don_d1997 3 місяці тому

    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".

  • @lw9954
    @lw9954 2 роки тому +1

    Ty bro

  • @tunkit7248
    @tunkit7248 3 роки тому +1

    Thanks bro

  • @lm2thed142
    @lm2thed142 8 місяців тому +1

    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:

  • @beingzero7541
    @beingzero7541 2 роки тому +1

    Wow!

  • @ТодорПарушев-и8ч
    @ТодорПарушев-и8ч 6 місяців тому

    thanks

  • @piotrkopcewicz5227
    @piotrkopcewicz5227 Рік тому +1

    nice tutorial :)

  • @huntercraft5674
    @huntercraft5674 Рік тому +1

    cool, Bro

  • @EissaAlahdul
    @EissaAlahdul 2 роки тому +1

    Thanks!

  • @tara2337
    @tara2337 6 місяців тому

    Cool

  • @bekturasanbekov1979
    @bekturasanbekov1979 Рік тому +1

    thx 4 vid bro !

  • @ahmetaydn4416
    @ahmetaydn4416 2 роки тому

    Gooo

  • @cristiucvladimir7909
    @cristiucvladimir7909 5 місяців тому

    Thanks Bro!

  • @bloomingtruth3399
    @bloomingtruth3399 Рік тому

  • @henriquefelinimena7433
    @henriquefelinimena7433 3 роки тому +1

    Thank you Bro!

  • @shricharanramesh7149
    @shricharanramesh7149 3 місяці тому

    Is color not a class variable ?

  • @Freyaris
    @Freyaris 2 роки тому +1

    thaaaaaaaaaaank you!!

  • @allamsrikanth3453
    @allamsrikanth3453 3 роки тому

    Looking for it since ages xd finally got it

  • @HussainAli-sb1dv
    @HussainAli-sb1dv 11 місяців тому

    love u

  • @igordjokic
    @igordjokic Рік тому

    My two cents!

  • @manashmahanta77
    @manashmahanta77 Рік тому

    Thanks bro

  • @tarikyassa1076
    @tarikyassa1076 3 роки тому +1

    Thanks Bro!