周志洋

个人站

持续学习 才能不被淘汰


Python实用技巧-类型注解基础

基本注解

from typing import List, Dict, Optional, Tuple

def top_k(nums: List[int], k: int) -> List[int]:
   return sorted(nums, reverse=True)[:k]

def find_user(users: Dict[int, str], uid: int) -> Optional[str]:
   return users.get(uid)

mypy 简介

pip install mypy
mypy your_project/


转载请注明:周志洋的博客 » Python实用技巧-类型注解基础

打赏一个呗

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦