Python's Assignment Expression (walrus operator)

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

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

  • @PatrickSoltani
    @PatrickSoltani Год назад +1

    This is an exemplary video of what's the nuts and bolts of an operator is and is not. Love the explanation and examples. Now if I could see something on 'tree', will be getting closer to Nirvana. Thank you Fred!

    • @mathbyteacademy
      @mathbyteacademy  Год назад +1

      Thanks Patrick, glad you liked the video.
      Can you explain a bit more what you mean by "tree" - like data structure trees?

  • @nitin.cherian
    @nitin.cherian Год назад

    Thank you Fred. It was an excellent explanation on the walrus operator. I have experienced the problem what walrus operator is trying to solve. Next time when I face the problem, I now know the solution.

  • @experimentalhypothesis1137
    @experimentalhypothesis1137 Год назад +1

    keep the channel up, it is very valuable

  • @tomer.nosrati
    @tomer.nosrati Год назад +1

    Learned something new today, thank you!

  • @MrBirjand
    @MrBirjand 5 месяцев назад

    Hi Fred, what are your thoughts about using the walrus operator for sentinel values in functions?
    This way, we wouldn’t need to introspect the function to get the `Object`.
    For example, instead of using this:
    def validate(a=object()):
    default_a = validate.__defaults__[0]
    we could do:
    def validate(a = ( default_a := object())):
    Do you think this would be bad practice?
    Maybe it makes the function signature convoluted?

    • @mathbyteacademy
      @mathbyteacademy  5 месяцев назад +1

      That's really interesting - never thought of using it that way. Honestly, I just use a global like SENTINEL = object() and use that throughout the functions in my module. Your way avoids using a global, but does make the signature confusing for someone who does not understand assignment expressions. I like it though; now I have to decide if I start using that in my code, or stick to the global! 😀

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

    Great video as always! A minor note: I think random.sample() should be used for hand instead of random.choices(), as the second uses replacement. Of course this not the point of the video :-)

    • @mathbyteacademy
      @mathbyteacademy  Год назад +1

      You are absolutely right - I should have used sample(), not choices() - thanks for pointing that out!

  • @karthikeyans3278
    @karthikeyans3278 Год назад +1

    Please upload case match video sir