简体   繁体   中英

Python 3 Not void function still returning None Type

I'm writing an initial fruitful function with a return value int. I then create a void function with a simple print statement in the body with no return value, therefore, None type. However when I create a third function that calls the fruitful function in the body, therefore the third function will return a value it's still a None type. I've read the stack previously questions here , here and here However, could not find a solution.

Here is my code:

def return_something():
    return 3

def return_void_test():
    print('VOID')

def return_void_filled():
    #This has inside a RETURN VALUE
    print(return_something())
    return_something()


 print(return_something()) 
 print(return_something)
 j = return_something()
 print(type(j),'\n')

 print(return_void_test())
 print(return_void_test)
 k = return_void_test()
 print(type(k),'\n')

 print(return_void_filled())
 print(return_void_filled)
 g = return_void_filled()
 print(type(g))

Here is the result:

3
<function return_something at 0x000001CEEF392E18>
<class 'int'> 

VOID
None
<function return_void_test at 0x000001CEF10247B8>
VOID
<class 'NoneType'> 

3
None
<function return_void_filled at 0x000001CEF133B6A8>
3
<class 'NoneType'>

Process finished with exit code 0

What am I doing wrong? Why the third function still shows as a None Type when it should be int(as Returns a value int 3)? Thanks

You aren't returning anything in your third function. You're only calling a function that does return something. Simply add a return

def return_void_filled():
    #This has inside a RETURN VALUE
    print(return_something())
    return return_something()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM