请问有人可以帮助我理解这个冒号在这里是做什么的吗?

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

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.

huangapple
  • 本文由 发表于 2023年6月29日 00:22:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76575059.html
匿名

发表评论

匿名网友

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

确定