1
00:00:00,000 --> 00:00:03,990
Functions can be used for a number of purposes and some times those purposes

2
00:00:04,000 --> 00:00:06,990
require the values be returned from the function.

3
00:00:07,000 --> 00:00:10,990
Let's take a look at how we return values from functions in Python.

4
00:00:11,000 --> 00:00:13,990
We start by making a working copy of functions.py.

5
00:00:14,000 --> 00:00:20,990
We will name it functions-working.py and we'll open that up and there we have

6
00:00:21,000 --> 00:00:22,990
our little test function.

7
00:00:23,000 --> 00:00:29,990
How about instead of printing this if we simply return it and then print it from

8
00:00:30,000 --> 00:00:32,990
up here and say print(testfunc())?

9
00:00:33,000 --> 00:00:39,990
So we'll save this and run it and there is our string.

10
00:00:40,000 --> 00:00:43,990
So all this function is doing is it's returning this string.

11
00:00:44,000 --> 00:00:48,990
The return keyword is the way that the values are written.

12
00:00:49,000 --> 00:00:57,990
The value itself comes after Return and it can be any type. We can return a number.

13
00:00:58,000 --> 00:01:00,990
Save that and run it and there is our number.

14
00:01:01,000 --> 00:01:09,990
We can return an object, say range(25), and that will return a range object.

15
00:01:10,000 --> 00:01:12,990
We'll save this and run it. And there is the range object.

16
00:01:13,000 --> 00:01:17,990
In fact, that range object is now usable as an iterator.

17
00:01:18,000 --> 00:01:29,990
So if I say for n in testfunc(): print(n, end=' ').

18
00:01:30,000 --> 00:01:31,990
Save that and run it.

19
00:01:32,000 --> 00:01:33,990
We've got that whole range.

20
00:01:34,000 --> 00:01:37,990
And you'll notice that just like a range is supposed to, it's non-inclusive and

21
00:01:38,000 --> 00:01:43,990
it does not include that last 25th object.

22
00:01:44,000 --> 00:01:49,990
So you can really return any object from a function using the return statement

23
00:01:50,000 --> 00:02:00,000
and that's done simply with return and then the object.

