python-3.x - python2中的函数注释
问题描述
python2.7中可以使用函数注解吗?
即这样的代码在python2.7中产生无效的语法,但在python3.5中有效
def apply(self, img_bgr) -> np.array:
^
SyntaxError: invalid syntax
解决方案
Python 类型提示是在PEP 484中引入的,在 Python 3.5 中实现。因此,它们在 Python 2.x(甚至 Python 3.4)上不可用。
另外,请注意Python 2 EOL - 我建议尽快从 Python 2 过渡。
推荐阅读
- azure - 在 Azure 函数 V1 中,如何使用 ConfigurationManager 检索 settings.json 值?
- python - 如何通过 Selenium Python 向搜索字段发送文本
- html - css中样式错误的div
- powershell - 在包含点的标签下编辑 web.config
- java - Android Studio 为 WorkManager 创建 LifecycleOwner 实例
- reactjs - 拖动后如何更改react-dnd中的drop组件?
- flutter - 两个包在颤振中使用两个不同的 compileSdkVersion
- python - matplotlib 中使用函数 z = f(x,y) 绘制曲面图,其中 f 不能用标准函数编写。如何?
- github - 如何在所有组织存储库中使用 GitHub 操作工作流?
- javascript - 如何将输入值推送到本地存储的数组中?