英文:
Can someone please help me understand what this colon is doing here?
问题
我看到一个视频,在Python中以一种不寻常的方式使用了冒号,但在Jupyter中复制该操作时,我无法弄清楚发生了什么:
x=0
i: x=9
print(i)
print(x)
我得到的结果是:
9
0
这里实际上发生了什么,i和x之间发生了什么,这里的基本操作是什么?
英文:
I saw a video that used a colon in an unusual way in Python, but replicating the operation in Jupyter, I can't figure out what is happening:
x=0
i: x=9
print(i)
print(x)
I get:
9
0
What is actually happening here with i and x, and what is the underlying operation here?
答案1
得分: 2
这是一个(无效的)类型提示。
要正确,应该是:
i: int = 9
但类型提示不影响正常执行,所以你不会看到程序行为有所不同。
英文:
It's an (invalid) type hint.
To be correct, it should be:
i: int = 9
But type hints don't affect normal execution, so you don't see the program behave differently.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论