void

void return type annotation

Python void return type annotation Question: In python 3.x, it is common to use return type annotation of a function, such as: def foo() -> str: return "bar" What is the correct annotation for the "void" type? I’m considering 3 options: def foo() -> None: not logical IMO, because None is not a type, def …

Total answers: 2

How can I return a default value for an attribute?

How can I return a default value for an attribute? Question: I have an object myobject, which might return None. If it returns None, it won’t return an attribute id: a = myobject.id So when myobject is None, the stament above results in a AttributeError: AttributeError: ‘NoneType’ object has no attribute ‘id’ If myobject is …

Total answers: 7