1
00:00:00,470 --> 00:00:01,850
Hello, dear friends.

2
00:00:02,300 --> 00:00:07,040
So something must have caught your attention since our first couple of lessons.

3
00:00:07,290 --> 00:00:07,520
Hmm.

4
00:00:08,150 --> 00:00:12,650
From the very first moment, we always talked about the concept of function.

5
00:00:13,610 --> 00:00:19,300
And moreover, in the code we wrote, we we used this word function.

6
00:00:19,310 --> 00:00:21,470
Well, what is the function?

7
00:00:21,480 --> 00:00:22,610
Break it down for me.

8
00:00:23,360 --> 00:00:23,660
All right.

9
00:00:23,780 --> 00:00:24,380
Let's have a look.

10
00:00:24,560 --> 00:00:25,340
Now is the time.

11
00:00:27,390 --> 00:00:29,760
So what is the function?

12
00:00:31,000 --> 00:00:39,160
So functions are structures that have certain functions in programming that we use repeatedly.

13
00:00:39,850 --> 00:00:46,030
For example, the function of the print function, which we have used since the very beginning of our

14
00:00:46,090 --> 00:00:50,620
works, is to print the values that we send onto the screen.

15
00:00:51,830 --> 00:00:53,090
So why do we need to use it?

16
00:00:54,560 --> 00:01:01,760
The task of the function is to bring together complex operations and it'll enable us to perform these

17
00:01:01,760 --> 00:01:02,540
operations.

18
00:01:02,690 --> 00:01:04,160
Boom in one step.

19
00:01:05,510 --> 00:01:09,470
For example, the print function was written once by Python developers.

20
00:01:09,770 --> 00:01:13,730
And we can use it again and again and again and again in different parts of our programs.

21
00:01:14,700 --> 00:01:21,080
So it's by using functions that we can combine one or more steps into one name.

22
00:01:22,200 --> 00:01:25,770
The function only runs when it's called Just Like My Dog.

23
00:01:27,030 --> 00:01:31,350
Now, are there any more built in functions in the Python library like print?

24
00:01:33,120 --> 00:01:33,600
That's right.

25
00:01:33,990 --> 00:01:37,950
Python gives us many, many, many built in functions in his library.

26
00:01:38,310 --> 00:01:40,200
But we can also create our own functions.

27
00:01:41,280 --> 00:01:43,890
So how do you create a function and how do you use it?

28
00:01:44,640 --> 00:01:45,030
All right.

29
00:01:45,570 --> 00:01:46,710
Let's see by example.

30
00:01:47,910 --> 00:01:52,830
Let's define a function named some with death as our key word.

31
00:01:54,940 --> 00:01:57,670
And give two parameters, A and B.

32
00:01:58,650 --> 00:02:01,890
Now, at the end, we do have to put a Colan mark.

33
00:02:03,870 --> 00:02:06,810
And now we can use here a docstring.

34
00:02:07,890 --> 00:02:09,480
Wait, here's another one.

35
00:02:09,690 --> 00:02:10,740
What's the docstring?

36
00:02:11,190 --> 00:02:15,270
All right, docstring specifies what the function does.

37
00:02:15,480 --> 00:02:16,260
It's optional.

38
00:02:17,220 --> 00:02:18,360
If you want to, you can add it.

39
00:02:18,360 --> 00:02:20,040
If not, you don't have to.

40
00:02:20,050 --> 00:02:22,510
It's not necessarily necessary.

41
00:02:22,950 --> 00:02:29,550
But if a different programmer wants to use your functions, they'll be able to know what the function

42
00:02:29,550 --> 00:02:30,030
does.

43
00:02:30,360 --> 00:02:30,690
Get it.

44
00:02:30,960 --> 00:02:31,320
Cool.

45
00:02:31,680 --> 00:02:33,060
Now let's continue.

46
00:02:34,500 --> 00:02:39,330
Here we take the functions task print A plus B.

47
00:02:43,160 --> 00:02:44,580
Now, are functions ready?

48
00:02:44,630 --> 00:02:48,680
So let's try some for five.

49
00:02:51,030 --> 00:02:51,990
The result is nigh.

50
00:02:53,000 --> 00:02:56,060
Oh, way simple right now.

51
00:02:56,300 --> 00:02:58,010
That's not all we've got here.

52
00:02:58,670 --> 00:03:01,760
We can now talk about return statement and functions.

53
00:03:02,510 --> 00:03:04,220
So what are return statements then?

54
00:03:05,300 --> 00:03:12,290
The return statement means that the function returns a value to the place where it was called after

55
00:03:12,290 --> 00:03:13,070
the operation.

56
00:03:13,670 --> 00:03:15,110
OK, I'm going to read your mind again.

57
00:03:15,140 --> 00:03:17,090
So why do we need to use it?

58
00:03:17,810 --> 00:03:24,800
Because we can store the value that we receive in the function in a variable and use the variable elsewhere

59
00:03:24,800 --> 00:03:26,390
in the program you follow.

60
00:03:27,500 --> 00:03:28,430
I'll give you an example.

61
00:03:29,400 --> 00:03:33,780
We define a function named sum and give it four parameters.

62
00:03:42,260 --> 00:03:45,920
The task of this function is this summer to give an argument, right?

63
00:03:51,050 --> 00:03:57,560
Now we define another function named multiply and give one as a parameter to it.

64
00:03:58,720 --> 00:04:02,920
Now, the task of this function is multiplying the argument with two.

65
00:04:18,540 --> 00:04:21,720
So as you can see, both the functions will work smoothly.

66
00:04:22,440 --> 00:04:30,090
But what if we want to use the result of the some function as an argument to the multiple function?

67
00:04:42,560 --> 00:04:43,700
Yeah, we're going to get an error.

68
00:04:44,360 --> 00:04:48,530
So at this point, what if we use a return statement?

69
00:04:49,280 --> 00:04:50,390
That's how we get it.

70
00:04:51,080 --> 00:04:51,620
Let's try it.

71
00:04:52,680 --> 00:04:58,760
Def some parenthesis a, b, c, d, parentheses.

72
00:04:58,980 --> 00:04:59,520
Colon.

73
00:05:00,860 --> 00:05:05,030
Return A plus B, plus C, plus D.

74
00:05:07,450 --> 00:05:11,530
Death, multiply parentheses, a Prentice's colon.

75
00:05:14,600 --> 00:05:18,020
Return a asterisk to.

76
00:05:23,330 --> 00:05:24,290
Multiply.

77
00:05:27,000 --> 00:05:27,660
Some.

78
00:05:29,000 --> 00:05:29,600
Parentheses.

79
00:05:33,770 --> 00:05:36,570
12, 14, 13.

80
00:05:36,590 --> 00:05:37,430
Because Brent says.

81
00:05:39,400 --> 00:05:41,680
The result is 98.

82
00:05:42,250 --> 00:05:43,570
Did you do that in your head, too?

83
00:05:44,170 --> 00:05:44,860
But that's it.

84
00:05:44,950 --> 00:05:45,580
You got it.

85
00:05:46,910 --> 00:05:50,870
All right, so are you ready for another one because we got one more topic and functions.

86
00:05:51,290 --> 00:05:53,780
It's called the lambda expression.

87
00:05:54,320 --> 00:05:54,740
All right.

88
00:05:55,460 --> 00:05:56,900
So what is the lambda expression?

89
00:05:58,130 --> 00:06:00,770
It's also called an anonymous function.

90
00:06:02,050 --> 00:06:05,140
Now we can define it with lambda expressions.

91
00:06:05,950 --> 00:06:11,680
So what's the difference then, between normal functions and a lambda expression?

92
00:06:12,640 --> 00:06:18,670
I'll tell you with a LAMDA expression, we can define a function in one line, lambda expressions can

93
00:06:18,670 --> 00:06:23,740
be used, especially when it's troublesome to write a short function with def.

94
00:06:24,730 --> 00:06:30,610
So Lambda function can take any number of arguments, but it can only have one expression.

95
00:06:31,180 --> 00:06:31,510
Get it.

96
00:06:32,410 --> 00:06:39,070
So the power of Lambda is better shown when you use them as an anonymous function inside of another

97
00:06:39,070 --> 00:06:39,490
function.

98
00:06:40,060 --> 00:06:41,560
Oh, OK.

99
00:06:41,560 --> 00:06:42,340
So how do we use it?

100
00:06:42,400 --> 00:06:43,000
Let me show you.

101
00:06:44,160 --> 00:06:47,760
As you know, in Python, we define a function with the deaf statement.

102
00:06:48,270 --> 00:06:54,210
Deaf some princes, a, B, princes Colan return A plus B.

103
00:06:55,020 --> 00:07:00,900
So this function aggregates have parameters given to each other and then returns as some of them some.

104
00:07:01,850 --> 00:07:03,140
10 14.

105
00:07:03,530 --> 00:07:05,300
The result is 24.

106
00:07:06,240 --> 00:07:10,620
So if we want to do the same with the help of the lambda function, how do we proceed?

107
00:07:11,370 --> 00:07:12,450
Watch closely.

108
00:07:13,390 --> 00:07:15,220
Some underscore one equals.

109
00:07:16,560 --> 00:07:17,340
Lambda.

110
00:07:18,440 --> 00:07:21,890
A B, colon, A, plus B.

111
00:07:24,890 --> 00:07:26,240
Some underscore one.

112
00:07:27,480 --> 00:07:28,590
Princess 10.

113
00:07:30,170 --> 00:07:32,150
Fourteen close friends.

114
00:07:32,720 --> 00:07:34,580
The result is 24.

115
00:07:36,410 --> 00:07:42,530
So Lambda functions are one of the advanced functions of the python programming language.

116
00:07:42,860 --> 00:07:44,960
And you just cracked the code.

117
00:07:46,200 --> 00:07:53,370
So that's it in this lesson, we have learned the function logic in Python and how it works.

118
00:07:54,300 --> 00:07:58,680
But we also talked a little bit about the return statement and the lambda expression.

119
00:07:58,770 --> 00:08:01,350
So we're going to put a few of these things together in the next lesson.

120
00:08:02,010 --> 00:08:02,880
I want to see there.

121
00:08:03,840 --> 00:08:04,680
Have a nice day.
