Linux 拨号vps windows公众号手机端

python怎么设置函数注解

lewis 6年前 (2019-03-22) 阅读数 11 #程序编程
文章标签 python

在python中设置函数注解,具体方法如下:

def clip(text:str, max_len:'int > 0'=80) ->str: # 有注解的函数声明

end = None

if len(text) > max_len:

space_before = text.find(' ', 0, max_len)

if space_before >= 0:

end = space_before

else:

space_after = text.find(' ', max_len)

if space_after >= 0:

end = space_after

if end is None: # 没找到空格

end = len(text)

return text[:end].strip()

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门