Valid Python line with undefined variable and annotation

huangapple go评论63阅读模式
英文:

Valid Python line with undefined variable and annotation

问题

我遇到了一个帖子,其中有一个带有一些类型注释的未定义变量名。 这一行是有效的。 它是什么,有哪些可能的用途?

>>> x: int
>>> x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
英文:

I have come accros a post with undefined variable name with some type annotation. The line is valid. What it does and what are possible usages?

>>> x: int
>>> x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined

答案1

得分: 1

Type hinting a variable gives static type checkers an idea of what type a variable is going to be, before it is assigned with anything.

英文:

Type hinting a variable gives static type checkers an idea of what type a variable is going to be, before it is assigned with anything:
Valid Python line with undefined variable and annotation

huangapple
  • 本文由 发表于 2023年4月19日 14:46:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76051467.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定