Type Hinting Makes Your Code More Professional
ฝัง
- เผยแพร่เมื่อ 1 ส.ค. 2024
- In this video we learn why type hinting makes your Python code more professional and how to do it.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: www.neuralnine.com/books/
💻 The Algorithm Bible Book: www.neuralnine.com/books/
👕 Programming Merch: www.neuralnine.com/shop
🌐 Social Media & Contact 🌐
📱 Website: www.neuralnine.com/
📷 Instagram: / neuralnine
🐦 Twitter: / neuralnine
🤵 LinkedIn: / neuralnine
📁 GitHub: github.com/NeuralNine
🎙 Discord: / discord
🎵 Outro Music From: www.bensound.com/
Timestamps
(0:00) Intro
(0:17) Type Hinting Basics
(6:17) Collection Types
(9:28) Custom Types
(13:26) Advanced Types
(19:42) Generics & Type Variables
(24:03) Outro - วิทยาศาสตร์และเทคโนโลยี
Nice video.
Also, one of the best advantages of type hinting is that you can benefit from IntelliSense / code suggestions in the function body for a variable which is passed to the function as parameter.
I'm using type hinting, but that's totally different level. Great
Thank you very nice 👍🏼
Optional isn't a fancy way to mark optional function parameters.
It means the value can be None. Optional[T] is simply Union[T, None]
What about returns or inputs with numpy?
Extra thing I've learnt recently - you use the following to not do imports just for typing.
Also types surrounded by semicolons is a legit syntax and can be used for types which won't be imported during execution.
if typing.TYPE_CHECKING:
from my_module import MyClass
def myfunc(arg1: "MyClass"):
pass
Thx.
Since 3.10 you can also do
----
def myfunction(myparam: int | float) -> int | float:
----
instead of
----
from typing import Union
def myfunction(myparam: Union[int, float]) -> Union[int, float]:
----
Yes, best thing is to make mypy kind of module inbuilt in standard lib
Have you ever considered learning Rust? Nice video btw!
He has rust tutorials
@@notnalin Really where?
@@aymancassim8944 th-cam.com/play/PLzMcBGfZo4-nyLTlSRBvo0zjSnCnqjHYQ.html
My brain are brokenn ;-;
The intro is too loud in comparison to the rest of the video. This has been a problem for a long time now.
i think it's fine, i mean most people skip it anyways :P