2

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?

  • Do the answers to this [question](https://stackoverflow.com/questions/32557920/what-are-type-hints-in-python-3-5) help at all? – quamrana Jun 28 '23 at 16:24

1 Answers1

2

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.

Kache
  • 15,647
  • 12
  • 51
  • 79