美文网首页
2021-05-31--Python2

2021-05-31--Python2

作者: Amant_8bb4 | 来源:发表于2021-05-31 10:54 被阅读0次

def solution(n: int = 600851475143) -> int:#->int后面的冒号是函数定义def的用法

##  ->int是python返回类型的注解,参数后面的冒号是注解信息

#这句话的意思即为定义了一个函数名为solution,其中给定一个参数n,n为600851475143

#solution这个函数的返回值为int

try:

        n = int(n)

    except (TypeError, ValueError):

        raise TypeError("Parameter n must be int or passive of cast to int.")

        #raise语法:raise [Exception [, args [, traceback]]]语句中TypeError是异常的 类型

        #括号里面是错误信息

    if n <= 0:

        raise ValueError("Parameter n must be greater or equal to one.")

相关文章

  • 2021-05-31--Python2

    def solution(n: int = 600851475143) -> int:#->int后面的冒号是函数...

网友评论

      本文标题:2021-05-31--Python2

      本文链接:https://www.haomeiwen.com/subject/ufovsltx.html