英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论