V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
zywscq
V2EX  ›  Python

9 个 Python 中比较复杂的类型注解总结

  •  
  •   zywscq · 9 天前 · 1688 次点击
    1. TypeVar: 声明类型变量
    2. NewType:基于既有类型定义新类型
    3. Final Type:定义常量
    4. TypedDict:方便定义字典中键值对的类型
    5. Protocol:定义“鸭子类型”
    6. Union Type:一个变量,多种可能的类型
    7. Callable Types:定义函数等 Callable
    8. Annotated:除了类型之外,再加更多元数据
    9. TypeAlias:类型别名 原文链接: https://medium.com/techtofreedom/9-advanced-python-type-hints-that-will-improve-your-code-significantly-ae09ab3b3493?sk=829ad9b635a9422b8024b8ec383e0310
    8 条回复    2024-04-25 18:26:08 +08:00
    nagisaushio
        1
    nagisaushio  
       9 天前 via Android   ❤️ 4
    又来了,国外老哥
    LeeReamond
        2
    LeeReamond  
       9 天前   ❤️ 1
    @nagisaushio 外国小哥一文帮你弄懂 Python 类型注释
    gesse
        3
    gesse  
       9 天前
    免费好评
    sazima
        4
    sazima  
       9 天前
    还有 Generic 泛型
    zywscq
        5
    zywscq  
    OP
       9 天前
    @nagisaushio 哈哈哈,能说出这个梗的,都是老朋友了
    iorilu
        6
    iorilu  
       9 天前
    类型注解越来越复杂了, 不亚于又学一遍 python 阿
    chesha1
        7
    chesha1  
       8 天前
    这个帖子也没有总结啊,就是单纯把名字抛出来了,点进原文是自己写的付费文章,这种是否有推广的嫌疑?
    UN2758
        8
    UN2758  
       8 天前
    @iorilu 看看远方的 rust 的类型注解吧,也非常挠头
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   939 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 18:55 · PVG 02:55 · LAX 11:55 · JFK 14:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.