-3

I'm working on creating a function that returns the last_name, followed by a comma, a space, first_name another space, and finally last_name.

The below code gives me the correct answer:

def introduction(first_name, last_name):
  return last_name + ", " + first_name + " " + last_name

print(introduction("James", "Bond"))
Bond, James Bond

However, if I use print, I get the following:

def introduction(first_name, last_name):
  print(last_name + ", " + first_name + " " + last_name)

print(introduction("James", "Bond"))

Bond, James Bond
None
Angelou, Maya Angelou
None

Where does the none come from when using the print instead of return? I have looked around and I can't seem to tell which to use.

cigien
  • 57,834
  • 11
  • 73
  • 112
  • Does https://stackoverflow.com/questions/32312248/return-vs-print-list help? How about https://stackoverflow.com/questions/15300550/return-return-none-and-no-return-at-all ? – Karl Knechtel Apr 26 '20 at 23:17
  • 2
    Please don't make more work for others by vandalizing your posts. By posting on the Stack Exchange (SE) network, you've granted a non-revocable right, under a [CC BY-SA license](//creativecommons.org/licenses/by-sa/4.0), for SE to distribute the content (i.e. regardless of your future choices). By SE policy, the non-vandalized version is distributed. Thus, any vandalism will be reverted. Please see: [How does deleting work? …](//meta.stackexchange.com/q/5221). If permitted to delete, there's a "delete" button below the post, on the left, but it's only in browsers, not the mobile app. – Makyen May 08 '22 at 03:28

1 Answers1

2

None is what is returned by the function "print". That is, print sends something to stdout and then returns a None. You can verify this by explicitly returning the value and checking:

x = print('something')
print(x)

You introduction statement is returning a None, hence your statement

Print(introduction('James','Bond'))

First runs the introduction(,) which itself has a print statement that prints the name, but then returns a None, from which the print above prints.

Bobby Ocean
  • 3,120
  • 1
  • 8
  • 15