1
00:00:00,270 --> 00:00:04,920
Throughout all of yesterday, we've been using other people's classes.

2
00:00:05,460 --> 00:00:10,460
And we said that a class is simply just a blueprint for creating an eventual

3
00:00:11,490 --> 00:00:13,800
object. In this lesson,

4
00:00:13,830 --> 00:00:17,490
we're going to talk about how we can create our own classes,

5
00:00:17,970 --> 00:00:22,830
so our own blueprints, which we can use to create our own objects.

6
00:00:23,910 --> 00:00:28,080
Now let's go ahead and create our own custom classes in code.

7
00:00:28,530 --> 00:00:33,240
Go ahead and create a new project either in PyCharm or Repl.it wherever you

8
00:00:33,240 --> 00:00:37,140
prefer. And we're going to name it day-17-start,

9
00:00:37,950 --> 00:00:41,430
and then hit create. And again, as always,

10
00:00:41,460 --> 00:00:46,170
once you've created your project, it's time to create your first file

11
00:00:46,170 --> 00:00:48,090
which we're going to name main.py.

12
00:00:48,480 --> 00:00:52,890
And then we can collapse our project sidebar and focus on the code.

13
00:00:54,240 --> 00:00:59,070
So how do we create a class? The syntax looks very simple.

14
00:00:59,100 --> 00:01:05,120
You have the "class" keyword followed by the name of your class and then a colon

15
00:01:05,122 --> 00:01:05,123
.

16
00:01:05,129 --> 00:01:09,360
and then all of the code that's in your class will follow this and it will be

17
00:01:09,360 --> 00:01:13,320
indented. Let's create our very first class in Python.

18
00:01:13,920 --> 00:01:14,760
As I mentioned,

19
00:01:14,790 --> 00:01:19,440
the way that we would create a class is first by using the class keyword.

20
00:01:20,250 --> 00:01:22,740
And then we get to give our class a name.

21
00:01:23,220 --> 00:01:28,220
Let's say that we're building a website and we need a class to model our website's

22
00:01:29,490 --> 00:01:30,323
users.

23
00:01:30,570 --> 00:01:35,570
So this class is basically going to be the blueprint to represent what our

24
00:01:35,880 --> 00:01:39,450
users have and what they can do on our website.

25
00:01:40,170 --> 00:01:42,000
Let's call our class User

26
00:01:42,510 --> 00:01:47,510
and then we finished this declaration with a colon as usual. And everything

27
00:01:48,480 --> 00:01:50,010
else that's going to go inside

28
00:01:50,010 --> 00:01:54,180
this class is going to need to be indented after the colon.

29
00:01:54,870 --> 00:01:57,780
Let's start out with a completely empty class.

30
00:01:58,200 --> 00:02:02,820
Our user class is going to do absolutely nothing for now. However,

31
00:02:02,820 --> 00:02:04,530
because I've created my blueprint

32
00:02:04,620 --> 00:02:08,310
I can already use it to create my first user object.

33
00:02:08,940 --> 00:02:11,220
So let's say I wanted to create a user_1

34
00:02:11,640 --> 00:02:14,490
and I'm going to create it using that class,

35
00:02:14,880 --> 00:02:17,760
which notice it's now being recognized by PyCharm,

36
00:02:18,150 --> 00:02:21,330
and it's got the C symbol next to it. And of course,

37
00:02:21,330 --> 00:02:23,850
to initialize an object from a class,

38
00:02:23,880 --> 00:02:26,190
we have to add the parentheses at the end.

39
00:02:26,940 --> 00:02:31,020
Now we get an error here because there's an indent expected.

40
00:02:31,440 --> 00:02:33,540
So basically Python doesn't like it

41
00:02:33,630 --> 00:02:38,340
when you create something like a class or when you create something like a

42
00:02:38,340 --> 00:02:40,950
function and you have a colon,

43
00:02:41,280 --> 00:02:46,080
but you don't have anything inside that function or class. For example,

44
00:02:46,080 --> 00:02:49,560
if I just immediately wanted to print "hello" afterwards,

45
00:02:49,590 --> 00:02:52,650
I get exactly the same error; indent expected.

46
00:02:53,100 --> 00:02:56,640
It's expecting this function that you've created or this class

47
00:02:56,640 --> 00:03:01,640
you've just created to have some sort of content before you go ahead and do something

48
00:03:01,810 --> 00:03:04,630
else. So how can we fix this? Well,

49
00:03:04,660 --> 00:03:08,200
if we actually really want to leave this function or this class empty,

50
00:03:08,320 --> 00:03:10,390
we can use a keyword which is pass.

51
00:03:10,960 --> 00:03:15,370
And all it does is it just passes. It says, I don't want to have a go right now.

52
00:03:15,640 --> 00:03:19,840
Just continue to the next line of code. And this gets rid of our errors

53
00:03:19,900 --> 00:03:21,880
both in the function declaration

54
00:03:22,210 --> 00:03:26,650
as well as in our class declaration. We've now essentially completed the

55
00:03:26,650 --> 00:03:29,050
first step towards creating our custom classes,

56
00:03:29,320 --> 00:03:34,320
which is writing the declaration and then building an object called user_1 out

57
00:03:34,960 --> 00:03:39,370
of that class. And we've also seen how to name classes in Python.

58
00:03:39,940 --> 00:03:43,960
Now the name of the class should have the first letter of every word

59
00:03:44,140 --> 00:03:44,980
capitalized.

60
00:03:45,550 --> 00:03:50,550
And this particular style of naming in Programming is known as Pascal case.

61
00:03:52,060 --> 00:03:55,030
So if you think of Blaise Pascal as a person,

62
00:03:55,060 --> 00:03:56,950
then we know that everybody's name,

63
00:03:56,950 --> 00:04:01,950
every person's name, has the first letter capitalized and also the first letter

64
00:04:02,400 --> 00:04:04,890
of their surname or their middle name

65
00:04:04,980 --> 00:04:08,100
and basically every subsequent name capitalized. Now,

66
00:04:08,130 --> 00:04:12,180
this is different from another type of casing which you may have come across

67
00:04:12,420 --> 00:04:13,800
which is called camel casing.

68
00:04:14,160 --> 00:04:19,160
And camel casing is only different from Pascal case because the first word is

69
00:04:19,380 --> 00:04:23,910
lowercase, but every subsequent word it has it's first letter capitalized in

70
00:04:24,030 --> 00:04:27,870
exactly the same way as Pascal case. And finally,

71
00:04:27,900 --> 00:04:31,590
we've also come across snake case where all the words are lowercase

72
00:04:31,740 --> 00:04:32,880
but they're separated by 

73
00:04:32,880 --> 00:04:37,830
an underscore. In Python programming, you won't see a lot of camel casing.

74
00:04:37,860 --> 00:04:41,430
You will see Pascal case being used for the class names,

75
00:04:41,760 --> 00:04:45,210
snake case being used pretty much to name everything else.

