+ 3
What is this expression in python ?
What is this expression in the code ? What does it mean ? https://code.sololearn.com/cIPNZ9NxxwF1/?ref=app
3 Respostas
+ 4
That's a so-called annotation, specifying which type is supposed to be passed to the argument.
It's basically an optional tool to optically keep track of what's going on, when the programs become larger.
It does not do anything directly, but you can access these annotations from the function(animal.__annotations__) and involve the stored information in your code.
+ 4
HonFu does this mean that passing an integer to animal() raises an error ?
+ 2
No, it doesn't.
But you can force this behavior anyway, if you want to, even without annotations, for example by writing:
if not isinstance(arg, list):
raise TypeError
Or something like that.