Python Type Hinting

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 มิ.ย. 2022
  • An overview of type hinting, including generics, in Python.
    #mathbyteacademy #python
    Code for this Video
    ================
    Available in GitHub blog repo: github.com/fbaptiste/python-blog
    Direct link: tinyurl.com/4vz6u6st
    My Python Courses
    =================
    - Python 3 Fundamentals (introduction to Python)
    www.udemy.com/course/python3-...
    - Python 3 Deep Dive (Part 1 - Functional)
    www.udemy.com/course/python-3...
    - Python 3 Deep Dive (Part 2 - Iteration, Generators)
    www.udemy.com/course/python-3...
    - Python 3 Deep Dive (Part 3 - Hash Maps)
    www.udemy.com/course/python-3...
    - Python 3 Deep Dive (Part 4 - OOP)
    www.udemy.com/course/python-3...

ความคิดเห็น • 31

  • @rekeshwardhanani920
    @rekeshwardhanani920 2 ปีที่แล้ว +12

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

  • @MohamedAhmed-rf5bk
    @MohamedAhmed-rf5bk ปีที่แล้ว +1

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

  • @raviranjan2823
    @raviranjan2823 ปีที่แล้ว +2

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

  • @D_Analyst007
    @D_Analyst007 ปีที่แล้ว

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

  • @PictorialPlanet
    @PictorialPlanet ปีที่แล้ว

    Great instruction, Fred, thank you!

  • @IlyaIlya_lopkop
    @IlyaIlya_lopkop 2 ปีที่แล้ว

    great video

  • @hytgohg7169
    @hytgohg7169 หลายเดือนก่อน

    I put like then start watching

  • @AlexanderDemin
    @AlexanderDemin 2 ปีที่แล้ว

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

    • @mathbyteacademy
      @mathbyteacademy  2 ปีที่แล้ว +6

      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 2 ปีที่แล้ว +3

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

    • @mathbyteacademy
      @mathbyteacademy  2 ปีที่แล้ว +6

      That's on my list of future videos, yes.

  • @rolfjohansen5376
    @rolfjohansen5376 11 หลายเดือนก่อน

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

    • @mathbyteacademy
      @mathbyteacademy  11 หลายเดือนก่อน

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

  • @BernardoDionisi
    @BernardoDionisi 8 หลายเดือนก่อน

    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.

    • @mathbyteacademy
      @mathbyteacademy  8 หลายเดือนก่อน +1

      Thanks!
      Generics is on my to do list for a future video.

    • @BernardoDionisi
      @BernardoDionisi 8 หลายเดือนก่อน

      Grazie mille :)

  • @Ibo-dq2km
    @Ibo-dq2km 4 หลายเดือนก่อน

    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  4 หลายเดือนก่อน +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)

  • @abhi.isnt.awesome
    @abhi.isnt.awesome 7 หลายเดือนก่อน +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  7 หลายเดือนก่อน +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 7 หลายเดือนก่อน

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

  • @Absimilard
    @Absimilard ปีที่แล้ว

    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  ปีที่แล้ว +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 ปีที่แล้ว

      @@mathbyteacademy thank you very much for the clarification!

  • @chriskeo392
    @chriskeo392 11 หลายเดือนก่อน

    Did you ever make the pydantic video?

    • @mathbyteacademy
      @mathbyteacademy  11 หลายเดือนก่อน

      yes, it's in the channel videos