4 ms·
What I don't understand is why it's not: def greeting(name: str): str: or: def greeting(name: str): str Using once ":" and then "->" for type declar
by nikolay 11y ago
What I don't understand is why it's not:
def greeting(name: str): str:
or:
def greeting(name: str): str
Using once ":" and then "->" for type declaration is inconsistent. Not to mention that the dash is not always aligned with the tip of the ">" and it looks ugly, not like a real arrow!
- ghshephard 11y agoThe name: implies that the type of the "name" object is str. If you were consistent, then, def greeting(...):str would imply that the type of the greeting object is str, which is definitely not the case (it is "function"). The -> isn't defining the type, it's specifying what is returned.
- nikolay 11y agoBut it's not the name alone, it's the name with the signature. `greeting` might be `function`, but `greeting("nikolay")` type would be `str`.