1
00:00:00,009 --> 00:00:00,490
All right.

2
00:00:00,500 --> 00:00:05,739
So welcome to this brand new section where we're going to take a look at functions

3
00:00:06,039 --> 00:00:07,829
and so far so good.

4
00:00:08,029 --> 00:00:09,649
We've actually been working with quite a

5
00:00:09,659 --> 00:00:12,989
number of prebuilt functions within Python.

6
00:00:13,220 --> 00:00:17,690
So functions like the print input range and so on,

7
00:00:17,840 --> 00:00:21,639
they all perform a particular kind of operation.

8
00:00:22,000 --> 00:00:26,709
However, what if we wanted to create our very own custom functions?

9
00:00:26,719 --> 00:00:28,989
How can we do that well to do? So

10
00:00:29,200 --> 00:00:31,379
we are going to have to

11
00:00:31,569 --> 00:00:34,860
define the name of the function first of all

12
00:00:35,270 --> 00:00:37,009
and then decide whether or not that function

13
00:00:37,020 --> 00:00:40,180
is going to accept what we call parameters.

14
00:00:40,669 --> 00:00:42,099
And then we can also say, OK,

15
00:00:42,110 --> 00:00:46,000
this function will add these numbers or is going to do something.

16
00:00:46,250 --> 00:00:51,860
And then finally, we can choose to return a value within that function. So

17
00:00:52,119 --> 00:00:53,349
it's going to be something like this. OK?

18
00:00:53,360 --> 00:00:57,900
You will have the def which is going to be the function to define

19
00:00:58,310 --> 00:01:03,049
the name of the function. And then you can, you can choose to have parameters

20
00:01:03,380 --> 00:01:05,440
inside of that function.

21
00:01:05,910 --> 00:01:06,529
OK?

22
00:01:06,839 --> 00:01:07,569
And then

23
00:01:07,680 --> 00:01:10,209
we'll have the function body.

24
00:01:10,220 --> 00:01:14,029
So you know, add A plus B, add this,

25
00:01:14,040 --> 00:01:17,430
do this divide this check to see if this loop is true, you know, stuff like that,

26
00:01:17,440 --> 00:01:19,430
basically whatever the, the function will do.

27
00:01:19,690 --> 00:01:20,730
And then finally,

28
00:01:21,480 --> 00:01:23,180
we can then choose to return

29
00:01:23,750 --> 00:01:25,940
a value, which by the way,

30
00:01:26,349 --> 00:01:29,300
this is going to be optional,

31
00:01:29,680 --> 00:01:35,690
we don't always have to return a value whenever we are creating our own function.

32
00:01:35,760 --> 00:01:37,660
Let me give you a very, very basic example.

33
00:01:37,669 --> 00:01:39,400
So let's say for example, we wanted to create

34
00:01:39,620 --> 00:01:40,690
a function

35
00:01:40,949 --> 00:01:42,059
that will print

36
00:01:42,389 --> 00:01:44,620
the words hello world.

37
00:01:44,860 --> 00:01:45,500
All right,

38
00:01:46,160 --> 00:01:50,139
we can say DF and then I can call my function greet.

39
00:01:50,500 --> 00:01:52,230
So the name of my function is going to be

40
00:01:52,239 --> 00:01:56,480
greet and then I can add my brackets at the colon

41
00:01:56,970 --> 00:01:57,849
and then enter,

42
00:01:58,349 --> 00:02:03,220
by the way, notice that I haven't added any parameters inside of the

43
00:02:03,339 --> 00:02:04,690
brackets in here.

44
00:02:04,900 --> 00:02:06,360
Parameters are optional.

45
00:02:07,230 --> 00:02:08,020
However,

46
00:02:08,110 --> 00:02:11,740
I'm gonna come in right now and then define what the function will actually do.

47
00:02:11,750 --> 00:02:13,210
So I'm gonna say print.

48
00:02:14,270 --> 00:02:15,039
Now,

49
00:02:15,250 --> 00:02:18,789
I'm going to provide the words hello

50
00:02:19,190 --> 00:02:20,130
world.

51
00:02:21,220 --> 00:02:23,220
And now all I would have to do

52
00:02:23,460 --> 00:02:26,479
is to simply call the function.

53
00:02:26,800 --> 00:02:28,940
And how do I do that? I'm gonna say greet

54
00:02:29,449 --> 00:02:30,649
and then the packets.

55
00:02:31,210 --> 00:02:32,000
And if it is,

56
00:02:32,729 --> 00:02:36,070
so now if I was to run the program, there you go.

57
00:02:36,220 --> 00:02:38,759
It simply says hello world.

58
00:02:39,179 --> 00:02:43,130
So once again, we started off by giving the name

59
00:02:43,389 --> 00:02:45,630
greet to our function.

60
00:02:46,429 --> 00:02:48,929
And then we're now told what the function should do.

61
00:02:48,940 --> 00:02:54,910
The function should print Hello world. Whenever we call or use that function.

62
00:02:55,029 --> 00:02:57,600
And then right here we simply call the

63
00:02:57,610 --> 00:02:59,970
function by simply saying greet and then in brackets

64
00:03:00,220 --> 00:03:00,770
and

65
00:03:00,949 --> 00:03:02,610
there you go.

66
00:03:02,779 --> 00:03:04,690
So this right here is

67
00:03:04,899 --> 00:03:08,940
one of the most basic kinds of functions we can create.

68
00:03:09,289 --> 00:03:10,229
But that's it, German.

69
00:03:10,270 --> 00:03:14,050
Even next video where we'll now begin to take a look at function parameters

70
00:03:14,220 --> 00:03:15,770
and arguments. I'll see you then.

