Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (12.7k points)

In python 3.x, it is entirely expected to utilize return type explanation of a capacity/function, for example, 

def foo() -> str:

    return "bar"

What is the right explanation for the "void" type?

I'm considering these three options:

def foo() -> None:

  • not logical IMO, because None is not a type,

def foo() -> type(None):

  • using the best syntax I know for obtaining NoneType,

def foo():

  • omit explicit return type information.

Choice 2. appears to be the most consistent to me, however, I've effectively seen a few occurrences of 1.


1 Answer

0 votes
by (26.4k points)

This is directly from PEP 484 - Type Hints documentation: 

When used in a type hint, the expression None is considered equivalent to type(None).

Also, as you can see the majority of the models utilize None as bring type back.     

Are you interested to learn the concepts of Python? Join the python training course fast!

Watch this video tutorial for more information

Related questions

0 votes
1 answer
asked Nov 19, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
asked Nov 12, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
asked Aug 6, 2019 in Java by Krishna (2.6k points)
0 votes
1 answer

Browse Categories