首页 > 编程语言 > 详细

Python def longestPalindrome(self, s: str) -> str: 函数功能注释 annotations

时间:2020-02-15 16:42:52      阅读:313      评论:0      收藏:0      [点我收藏+]

https://www.cnblogs.com/hongten/p/hongten_python_function_annotation.html

 

def f(ham: 42, eggs: int = spam) -> "Nothing to see here":
    print("Annotations:", f.__annotations__)
    print("Arguments:", ham, eggs)

#def关键字定义了函数f,在函数f中有两个参数:ham,eggs。
#其中ham没有默认值,而eggs是由默认值的,其默认值为‘spam‘.
#参数ham的注释部分为:42;参数eggs的注释部分为:int
# "Nothing to see here"是返回值的注释,这个必须用 ‘->‘连接

#看了java代码后,你会有更直观的认识,注释嘛,你可以根据你自己的想法,想怎么写就怎么写,如42,int;不过不好的注释有时候会给别人阅读代码带来很大的麻烦

#如果上面的代码是这样写:
def f(ham: int = 42, eggs: str = spam) -> Nothing to see here:
    print("Annotations:", f.__annotations__)
    print("Arguments:", ham, eggs)

#我想很多人阅读代码的时候就很容易理解啦 

 

Python def longestPalindrome(self, s: str) -> str: 函数功能注释 annotations

原文:https://www.cnblogs.com/focus-z/p/12312035.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!