Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NONE
#1
 
def entrada(e):
    if e == 1:
        aviso(e)
    else:
        return print(False)
  
def aviso(e):
        return print(True)
        
entrada(1)
When I run this, appears:

True
True
None

Why two 'True' and one 'NONE' !!!, I want just one 'True' ... or 'False'
Reply
#2
The function print() is used for its side effect (that it prints a line), not for its return value.

The expression return print("anything") is pretty confusing. It will print something to the screen, but it will return None.

Often it is better for functions to return their data and not print it themselves. Let the caller deal with the data and print it or not.

All of that said, I can't reproduce your output. The only statements that print are lines 5 and 8. While you return None, that return value never seems to be printed. When I run your program, I just get:

Output:
True
The True is printed from within aviso() as it returns, and then nothing else is printed.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020