def print_name(name):print(name)print(print_name('Annabel Lee'))
Why do I get the following output:
Annabel Lee
None
More precisely, from where does the word None
come from?
def print_name(name):print(name)print(print_name('Annabel Lee'))
Why do I get the following output:
Annabel Lee
None
More precisely, from where does the word None
come from?
You have two calls to print
: one inside print_name
and another outside the function's scope.
The one inside print_name()
prints the name
passed in. The one on the outside prints what the function print_name
returns - which is None
as you have no return
statement. Presuming you want only one printed output, you'd return
it instead of printing it in the function:
def print_name(name):return nameprint(print_name('Annabel Lee'))
Or just call print_name
without wrapping it in a print
function.