python函数注释
Python 函数 注释
2023-06-13 09:13:55 时间
函数注释是一个可选的功能,它允许在函数参数或者返回值中添加任意的元数据。无论是python本身还是标准库,都使用了函数注释。
def compile(source: 'something compilable',
filename: 'where the compilable thing comes from',
mode: 'is this a single statement or a suite?') -> bool:
return True
print(compile.__annotations__)
执行结果如下:
{'source': 'something compilable', 'filename': 'where the compilable thing comes from', 'mode': 'is this a single statement or a suite?', 'return': <class 'bool'>}
获取函数注释可以使用_annotations_方法。
相关文章
- Python基础22-并发编程
- python的random()函数用法_Python随机函数random用法示例
- python中bool函数_bool()函数以及Python中的示例
- python画图函数
- 《零基础学机器学习》笔记-第2课-数学和Python知识
- 【说站】python数组分割的函数
- 【说站】python正则表达式中分组的使用
- 【说站】python ReLU函数是什么
- 【说站】await在python协程函数的使用
- 【说站】python用circle函数画兔子的方法
- Django框架开发001期 Python+Django开发教程,开启你的第一个django网站应用
- Python基础语法-内置函数和模块-math模块
- Python类三种方法,函数传参,类与实例变量(一)详解编程语言
- Python学习:6.python内置函数详解编程语言
- Linux创建Python文件的步骤(linux新建python文件)
- python工具——wordcloud详解编程语言
- Python __import__()函数引入模块名
- Linux环境下Python开发的历程(linux与python)
- 在Linux上运行Python脚本的简单指南(linux运行python)
- Python连接MySQL数据库:初学者指南(python入mysql)
- Linux中如何离开Python环境(linux怎么退出python)
- 在Linux上安装Python学习快乐(linux下载python)
- python中的yield使用方法
- python进阶教程之函数对象(函数也是对象)