Python Type Hinting

Sdílet
Vložit
  • čas přidán 8. 09. 2024
  • An overview of type hinting, including generics, in Python.
    #mathbyteacademy #python
    Code for this Video
    ================
    Available in GitHub blog repo: github.com/fba...
    Direct link: tinyurl.com/4v...
    My Python Courses
    =================
    - Python 3 Fundamentals (introduction to Python)
    www.udemy.com/...
    - Python 3 Deep Dive (Part 1 - Functional)
    www.udemy.com/...
    - Python 3 Deep Dive (Part 2 - Iteration, Generators)
    www.udemy.com/...
    - Python 3 Deep Dive (Part 3 - Hash Maps)
    www.udemy.com/...
    - Python 3 Deep Dive (Part 4 - OOP)
    www.udemy.com/...

Komentáře • 33

  • @rekeshwardhanani920
    @rekeshwardhanani920 Před 2 lety +13

    Just like the Udemy courses, on point and informative. Waiting for Part 5 of Udemy series

  • @iwswordpress
    @iwswordpress Před měsícem

    So much useful info in such a short time!

  • @MohamedAhmed-rf5bk
    @MohamedAhmed-rf5bk Před rokem +1

    If you want to understand how something actually works, he is your man!

  • @raviranjan2823
    @raviranjan2823 Před 2 lety +2

    Made my day. Going to sleep today with satisfaction as learnt some good stuff.

  • @AlexanderDemin
    @AlexanderDemin Před 2 lety

    Fred, so great you have come back. Your 4 part Python course was amazing, but then you disappeared :-). Please, post!

    • @mathbyteacademy
      @mathbyteacademy  Před 2 lety +7

      Thanks, will do! Work has just been keeping me real busy - not enough time to create an entire course, so I thought this would be easier - I can just create videos and publish them one at a time.

  • @amidfallen
    @amidfallen Před 2 lety +3

    Oh man, thanks! Looking forward for that Pydantic video.
    By the way, I am curious, will you be doing some content about FastAPI?

  • @D_Analyst007
    @D_Analyst007 Před 2 lety

    Your videos are awesome, it gives all required info. Thanks for this high quality stuff!

  • @hytgohg7169
    @hytgohg7169 Před 3 měsíci

    I put like then start watching

  • @PictorialPlanet
    @PictorialPlanet Před rokem

    Great instruction, Fred, thank you!

  • @BernardoDionisi
    @BernardoDionisi Před 10 měsíci

    Fred! Thanks a lot for your videos and courses, they are such an incredible resource! I have request if time permits and you think it would be useful, would love to see a deep dive video on Python Generics. Maybe you already have it among all your videos and I missed it.

  • @IlyaIlya_lopkop
    @IlyaIlya_lopkop Před 2 lety

    great video

  • @Ibo-dq2km
    @Ibo-dq2km Před 6 měsíci

    32:30 concise it may be but not precise, we need iterables of iterables of exactly _two_ elements. Still need to add a comment or is there a way to express this through type hinting?
    Good video 👍

    • @mathbyteacademy
      @mathbyteacademy  Před 6 měsíci +1

      Well, you could use something like tuple[int|float, int|float] - this would specifically mandate that the elements be 2-element tuples of int or float. There might be other options available too, but to be honest I mainly use type hinting in conjunction with Pydantic to enforce those kinds of constraints, and there you can use annotated types. (I guess you could use an annotated type also, even without Pydantic, that way you have some sort of "documentation" that the type is a more general iterable of min_length = max_length = 2)

  • @rolfjohansen5376
    @rolfjohansen5376 Před rokem

    def func(*, a: int, ....) I missed why you did the star or * in parameter ,... else great work!!!!!

    • @mathbyteacademy
      @mathbyteacademy  Před rokem +1

      A * used this way indicates that what follows are keyword-only arguments (i.e. they must be passed in as named arguments).

  • @abhi.isnt.awesome
    @abhi.isnt.awesome Před 9 měsíci +1

    Hi Fred, thanks for the amazing lecture. I just bought your Pydantic V2 course. Before that I am on this video. I have a very basic doubt. Is List[Union[int, float]] the same thing as List[int | float]. The reason why am i asking this is because in my python version "int | float" is not working. Thanks in advanced

    • @mathbyteacademy
      @mathbyteacademy  Před 9 měsíci +1

      Yes, those are perfectly equivalent. That a | b syntax for type hints is available in Python 3.10 and up. I explain this in the Pydantic course when discussing nullable fields. Any reason why you are using a version of Python that is older than 3.10?
      (PEP for that change is here: peps.python.org/pep-0604/)

    • @abhi.isnt.awesome
      @abhi.isnt.awesome Před 9 měsíci

      @@mathbyteacademy Thanks for the clarification, Fred. I just forgot to update my python version xD.

  • @chriskeo392
    @chriskeo392 Před rokem

    Did you ever make the pydantic video?

  • @Absimilard
    @Absimilard Před rokem

    I have a question: what does the Asterix in your example def func(*, a: int, b: int = 0) do? is it a "shorthand" for *args?

    • @mathbyteacademy
      @mathbyteacademy  Před rokem +1

      The * symbol is used to indicate "no more positional arguments". So in this case, since no arguments were defined before the *, it means this function has no positional arguments, only keyword-only arguments.

    • @Absimilard
      @Absimilard Před rokem

      @@mathbyteacademy thank you very much for the clarification!