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 · 12 天前 · 1743 次点击

    腾讯云最新优惠活动来了:云产品限时1折,云服务器低至88元/年 ,点击这里立即抢购:9i0i.cn/qcloud,更有2860元代金券免费领取,付款直接抵现金用,点击这里立即领取:9i0i.cn/qcloudquan

    (福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

    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  
       12 天前 via Android   ?? 4
    又来了,国外老哥
    LeeReamond
        2
    LeeReamond  
       12 天前   ?? 1
    @nagisaushio 外国小哥一文帮你弄懂 Python 类型注释
    gesse
        3
    gesse  
       12 天前
    免费好评
    sazima
        4
    sazima  
       12 天前
    还有 Generic 泛型
    zywscq
        5
    zywscq  
    OP
       11 天前
    @nagisaushio 哈哈哈,能说出这个梗的,都是老朋友了
    iorilu
        6
    iorilu  
       11 天前
    类型注解越来越复杂了, 不亚于又学一遍 python 阿
    chesha1
        7
    chesha1  
       11 天前
    这个帖子也没有总结啊,就是单纯把名字抛出来了,点进原文是自己写的付费文章,这种是否有推广的嫌疑?
    UN2758
        8
    UN2758  
       10 天前
    @iorilu 看看远方的 rust 的类型注解吧,也非常挠头
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5544 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 05:59 · PVG 13:59 · LAX 22:59 · JFK 01:59
    Developed with CodeLauncher
    ? Do have faith in what you're doing.


    http://www.vxiaotou.com