repr in Python

Поделиться
HTML-код
  • Опубликовано: 16 ноя 2024

Комментарии • 16

  • @geoffy8245
    @geoffy8245 Год назад

    Clear and straight to the point! Thank you

  • @0xyu9
    @0xyu9 2 года назад +1

    love the simple explanation!!

  • @9934max
    @9934max 4 года назад

    Best explanation for repr

  • @kimaegaii
    @kimaegaii Год назад

    great explanation. finally i get it. keep it up the good work!

  • @atheenaantony7178
    @atheenaantony7178 3 года назад

    Best explanation 👌

  • @eliashawa968
    @eliashawa968 4 года назад

    Very good tutorial

  • @BrendanMetcalfe
    @BrendanMetcalfe 4 года назад

    Just found your channel. Thanks!

  • @sputniq2828
    @sputniq2828 3 года назад

    youre the best

  • @KumR
    @KumR 10 месяцев назад

    nice nice

  • @ofc_b4nk138
    @ofc_b4nk138 Год назад

    Thanks!!

  • @noeelreeds
    @noeelreeds 10 месяцев назад

    clear!

  • @ranisjsu6043
    @ranisjsu6043 5 лет назад

    Awesome....

  • @dillanteagle3726
    @dillanteagle3726 5 лет назад

    what if you also have __str__ . can you use __repr__ to change the it to any type() ? can you have __repr__ define a class representation as bytes but then also use __str__ to define string return value?

    • @yaron3479
      @yaron3479 4 года назад

      I don't get your question

    • @raghunandan5125
      @raghunandan5125 4 года назад

      the simplest way to go about it is to understand the goal of both of the methods:
      1) __repr__ has to return a string that is unambiguous i.e. it should return information on both the type of the object and the value that it holds.
      2) __str__ has to return a string that is printable i.e. it should return a value so that it looks good when printed.
      These are the conventions that are followed. However, when you are writing custom code you can always make everyone else's life difficult by returning non standard values which is not recommended.