Return statement not returning anything in python function

Answered

When I type a function with 'return' at the end nothing pops up in the output window for example:

Input:

def say_hello():
x = "Hello world"
return x

say_hello()

def say_hello2():
return "Hello world"

say_hello2()

Output:

/Users/disclosed/Desktop/Personal/Python/returnStatement/venv/bin/python /Users/disclosed/Desktop/Personal/Python/returnStatement/venv/returnstmnterror.py

Process finished with exit code 0

0
2 comments

please help!!!!

1

Python doesn't show what function returns in the output by default. You should use print() statements for that.

So instead of just calling say_hello function, you should do print(say_hello()).

0

Please sign in to leave a comment.