The last three lines print the return value from the "get_numbers"
function, which isn't returning anything. In python, the default
return value is None, and that's why you're seeing it.
On Thu, Jun 21, 2012 at 11:42 PM, Xander Solis <xrso...@gmail.com> wrote:
> Hello Python list,
> Noob here with a newbie question. I'm reading and working on the exercise of
> the book, Learn Python the Hard way 2.0. When I use this code, I get "None"
> on the output. My question is why does this happen?
On Thu, Jun 21, 2012 at 8:42 PM, Xander Solis <xrso...@gmail.com> wrote:
> Hello Python list,
> Noob here with a newbie question. I'm reading and working on the exercise of
> the book, Learn Python the Hard way 2.0. When I use this code, I get "None"
> on the output. My question is why does this happen?
> Noob here with a newbie question. I'm reading and working on the
> exercise of the book, Learn Python the Hard way 2.0. When I use this
> code, I get "None" on the output. My question is why does this happen?
Your function prints the number and then returns None (you have no
return statement in the function to change this) to the print statement.
If you want to have the function return a value, use the return
statement instead of print inside the function:
def func(some_value):
return some_value
x = func(5)
print x
<benjamin.kap...@case.edu> wrote:
> On Thu, Jun 21, 2012 at 8:42 PM, Xander Solis <xrso...@gmail.com> wrote:
>> Hello Python list,
>> Noob here with a newbie question. I'm reading and working on the exercise of
>> the book, Learn Python the Hard way 2.0. When I use this code, I get "None"
>> on the output. My question is why does this happen?
Xander Solis <xrso...@gmail.com> wrote:
> Noob here with a newbie question. I'm reading and working on the
> exercise of the book, Learn Python the Hard way 2.0. When I use this
> code, I get "None" on the output. My question is why does this happen?
> Noob here with a newbie question. I'm reading and working on the
> exercise of the book, Learn Python the Hard way 2.0. When I use this
> code, I get "None" on the output. My question is why does this happen?
None is the default return value for python-coded functions and python prints the value of expressions in interactive mode. Hmmm. But you seem to be running in batch mode. But where is 7.5 from. You must be doing more than shown.
Regardless, in my opinion, instead of printing, the function should return the computed value. You can then print the returned value. Real software should generally work that way. If nothing else, so you can automate tests instead of checking screen output.