# need clarification on void function vs value returning function~python

#### HCN1996

Joined Nov 29, 2015
25
Hello, I think I know what the difference is, but I havent been able to find a clear definition/example of each. I am posting my assignment code below which is supposed to have at least one value returning function, and one void function in it. I believe that I am using a value returning function with my functions slope() and/or slope2(). All the rest are void. Im not sure if I am right so any tips/further clarification would be greatly appreciated. My program works how it should, I am just looking for some help understanding functions from other eyes.

Last edited:

#### WBahn

Joined Mar 31, 2012
26,075
You say that you are using value returning functions with slope() and/or slope2(). Well, which is it?

You say you think you know the difference but give no indication of what you think that difference is.

The names are pretty descriptive. What do you think is required for a function to be a value-returning function?

#### HCN1996

Joined Nov 29, 2015
25
You say that you are using value returning functions with slope() and/or slope2(). Well, which is it?

You say you think you know the difference but give no indication of what you think that difference is.

The names are pretty descriptive. What do you think is required for a function to be a value-returning function?
I believe my value returning function is slope() and slope2() calls it. I have the impression that value returning functions are when a value is returned at the end and a void is when there is no return statement. However, I just have a feeling this isnt the case. Any help would be great. I know how to use functions well so far, but it bugs me that I dont completely know the difference between void and value returning functions. I would ask my teacher, but we are on spring break and I dont want to be a bother.

#### WBahn

Joined Mar 31, 2012
26,075
You basically have it.

A value-returning function is a function that returns a value.

A non-value-returning (i.e., void) function is a function that does not return a value.

It's as simple as that.

Now, one mistake your last post made is saying that it is void when there is no return statement.

While not having a return statement will definitely make it a non-value-returning function, this is not required. A 'return' statement that does not have a value simply returns without returning a value -- making it a non-value returning function (at least that time).

One problem (some say it's a feature -- and it can be) with Python is that the function definition doesn't spell out unambiguously whether it is value-returning or not.

Consider

Python:
def WhoKnows(x):
if (x > 100):
return 5 * x;
Whether WhoKnows() returns a value or not depends on the value of x.