1
00:00:00,560 --> 00:00:01,430
Hey, welcome back.

2
00:00:01,460 --> 00:00:04,580
In this video, you'll learn about static methods.

3
00:00:05,630 --> 00:00:10,430
Let's create a static method in the reservation ticket class.

4
00:00:11,000 --> 00:00:17,270
To create a static method, you use the static method decorator.

5
00:00:19,170 --> 00:00:21,930
A followed by the definition of the method.

6
00:00:23,930 --> 00:00:25,250
Let's say, convert.

7
00:00:26,760 --> 00:00:32,820
Now you see, that poncho didn't even suggest me to use a self argument.

8
00:00:32,820 --> 00:00:39,930
So static methods do not get a self argument or a c else argument.

9
00:00:40,200 --> 00:00:48,600
A static method is like a function, so it doesn't have any reference to the class.

10
00:00:49,540 --> 00:00:54,880
Or it's instance, let's say we have a mount as a variable.

11
00:00:56,520 --> 00:00:58,720
And return amount.

12
00:01:00,180 --> 00:01:02,280
Times 1.2.

13
00:01:03,470 --> 00:01:05,000
Now, what is this, anyway?

14
00:01:05,030 --> 00:01:06,800
Well, let's imagine that.

15
00:01:08,010 --> 00:01:17,310
We we are generating the ticket, but we need some utility function to convert the price from euros

16
00:01:17,310 --> 00:01:18,990
to USD.

17
00:01:19,350 --> 00:01:23,070
So this is some sort of utility function, right?

18
00:01:23,850 --> 00:01:33,150
But since this function is somehow related to producing the ticket, because we want to have that converted

19
00:01:33,150 --> 00:01:42,630
price inside the ticket, then it makes sense to have that method inside the class so that later on

20
00:01:43,110 --> 00:01:55,100
you can basically call that static methods using reservation ticket that converts.

21
00:01:55,110 --> 00:01:58,290
And here you'd give the amount like ten.

22
00:01:58,470 --> 00:02:07,440
Perhaps you store this in variable converted and then you can use the variable somewhere else in the

23
00:02:07,440 --> 00:02:08,100
code.

24
00:02:08,759 --> 00:02:12,780
But let's just print it out in here, print, convert it.

25
00:02:13,650 --> 00:02:15,510
And so we get 12.

26
00:02:16,250 --> 00:02:19,470
So ten times 1.2, we get 12.

27
00:02:19,490 --> 00:02:22,580
So that would be an example of a static method.

28
00:02:23,420 --> 00:02:31,370
Now, the distinction between static methods and class methods is a bit blurred, but usually you won't

29
00:02:31,370 --> 00:02:39,770
use static methods when you want to do some utilities like as we had here, converting that number.

30
00:02:39,770 --> 00:02:43,210
So conversions are usually a very used case.

31
00:02:43,220 --> 00:02:52,760
And so this method here is less associated with its class compared to this class methods.

32
00:02:54,290 --> 00:03:01,880
Both class methods and static methods are rarely used compared to instance methods, but it's good to

33
00:03:01,880 --> 00:03:03,760
know what they are.

34
00:03:03,770 --> 00:03:06,020
So I hope this makes sense.

35
00:03:06,020 --> 00:03:11,030
And in the next video you learn about magic methods which are very interesting.

36
00:03:11,030 --> 00:03:12,620
So I'll see you there.

