【问题标题】:What Does : Mean in Python? (NOT IN A LIST) [duplicate]什么是:在 Python 中是什么意思? (不在列表中)[重复]
【发布时间】:2021-01-14 14:40:17
【问题描述】:

我在互联网上看到了这段代码,我想知道这段代码中的: 是什么?

dispatcher : Dispatcher = Updater.dispatcher

【问题讨论】:

标签: python python-telegram-bot


【解决方案1】:

这是类型提示。

https://docs.python.org/3/library/typing.html

它帮助编码人员了解对象的预期类型是什么。此外,如果您尝试调用类对象的某些不受支持的方法,某些 linter 会显示错误,类似于静态编译器。

【讨论】:

  • 但是为什么当我写这个命令i : str = 123;print(type(i))我得到<class 'int'>时,它应该捕获错误吗?
  • @Jawad 这是类型-提示,而不是强制类型。 Python 仍然是一种鸭式语言,它只是帮助程序员避免产生可避免的错误。
猜你喜欢
  • 2015-02-13
  • 2017-01-07
  • 1970-01-01
  • 2020-10-27
  • 2015-07-15
  • 2018-07-17
  • 2012-08-13
  • 2020-06-05
  • 2011-04-16
相关资源
最近更新 更多