Python 3.7版本,函数的参数可以通过冒号来进行注释

def f(ham: str, eggs: str = 'eggs') -> str :
    print("Annotations:", f.__annotations__)
    print("Arguments:", ham, eggs)
    return ham + ' and ' + eggs

str 这里都表示注释,而不是强制确定的类型(Python是动态类型的)

冒号后表示参数的注释,如果需要默认赋值再在后面加等号即可

箭头后表示返回值的注释

 

参考:

https://www.cnblogs.com/Stitchez/p/10006519.html

相关文章:

  • 2022-01-12
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2021-12-24
  • 2021-06-15
猜你喜欢
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2021-07-26
相关资源
相似解决方案