2

I saw this code in the internet and I'm wounding what's : in this code?

dispatcher : Dispatcher = Updater.dispatcher
Jawad
  • 186
  • 1
  • 14

1 Answers1

2

It's type-hinting.

https://docs.python.org/3/library/typing.html

It helps the coder know what the object's intended type is. Also, some linter will shows error if you try to invoke some unsupported methods of a class object, similar to a static compiler.

kwkt
  • 1,058
  • 3
  • 10
  • 19
  • But why when I wrote this command ```i : str = 123;print(type(i))``` I got ``````, is it supposed to catch the error? – Jawad Jan 14 '21 at 15:01
  • 2
    @Jawad it's type-**hinting**, not type-forcing. Python is still a duck-typed language, it just helps programmers not create avoidable bugs. – kwkt Jan 14 '21 at 15:02