0

I found a function, where author used ":" colon when described parameters. What does ':' mean?

  def fit(self, x: np.array, y: np.array):
    pass

I tried to write same function

def F(x: int):
    print(x)

F('7')

When I tries to start it, it was no mistake, even though I used not integer x

  • More specific duplicate: https://stackoverflow.com/questions/54962869/function-parameter-with-colon – Thomas Nov 02 '22 at 13:20
  • It's part of the syntax for a function annotation, mostly commonly (and correctly, since PEP-484) to provide type hints. The runtime does not *enforce* the type hint; it's only there for external tools to perform static type checking. – chepner Nov 02 '22 at 13:21

0 Answers0