Python Forum
Why my function is returning None?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why my function is returning None?
#4
Oshadha Wrote: It is important that when returning a value, always return it as a variable, and not a line of code

This really isn't a correct thing to say at all. First, returning the value of any kind of expression is perfectly fine. An expression is something that can be evaluated to produce a value: examples are: a function call as in the OP's example, a literal (like 123 or "foo", or a variable.

The problem is that the print function returns None - since its job is to print to the screen, it doesn't make sense for it to return any meaningful value.
buran likes this post
Reply


Messages In This Thread
Why my function is returning None? - by PauloDAS - Jul-16-2022, 12:57 AM
RE: Why my function is returning None? - by Larz60+ - Jul-16-2022, 02:32 AM
RE: Why my function is returning None? - by Oshadha - Jul-16-2022, 03:10 AM
RE: Why my function is returning None? - by ndc85430 - Jul-16-2022, 09:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pausing and returning to function? wallgraffiti 1 2,203 Apr-29-2021, 05:30 PM
Last Post: bowlofred
  Why is the function returning None for a * b instead of number? omm 10 4,458 Nov-05-2020, 01:17 PM
Last Post: omm
  Having hard time understanding the function self-returning itself twice jagasrik 2 2,575 Aug-15-2020, 08:50 PM
Last Post: deanhystad
  Returning Value from Function with Trackbars vicpylon 3 2,129 May-24-2020, 11:28 PM
Last Post: bowlofred
  Nested Recursive Function not Returning Etotheitau 2 2,362 May-09-2020, 06:09 PM
Last Post: Etotheitau
  Function not returning correct value ActualNoob 3 2,785 Jan-11-2019, 12:35 AM
Last Post: stullis
  Function not returning expected value Euqinu 4 3,589 Sep-10-2018, 12:48 PM
Last Post: Euqinu
  Recursive function not returning expected output...(Python speech recog module) bigmit37 4 5,991 Jan-10-2017, 02:13 PM
Last Post: bigmit37
  function returning None tkj80 3 5,412 Oct-06-2016, 02:08 AM
Last Post: tkj80

Forum Jump:

User Panel Messages

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