Creating a Class
After the name of the class, you can put a colon (
:), and then on a new line that’s indented, you can write your class. And in this example, you’re just passing the
pass keyword, which is like a placeholder.
It just means nothing. It just, if you were to leave this blank, that would create an error. But if you leave
pass as a placeholder, then you can create this blank class. Now here’s another example.
We’ll just put in the
pass keyword as a placeholder now. Press Enter a couple more times, and we’ve got a class. If you just put in
Cat on the REPL, you’ll see that now a identifier for a class comes up on the output.
01:23 Now you’ll want to bear in mind that classes in Python have a naming convention. You don’t have to follow this. You can name classes in whatever way you want, but there are a lot of people using classes, and there is a convention that is called CapitalizedWords, or also CamelCase, or also PascalCase.
01:40 Every word is capitalized, including the first letter. There is no underscore between words. You just start with a new capital letter. CamelCase is sometimes understood as the first starting word not having a capital letter, but CamelCase is often used in both situations.
01:57 In any case, the key thing to take away from this is that when you’re creating a class, the convention is to start off with a capital letter, and then every word after that starts with a capital letter, no underscore or space between the words.
Become a Member to join the conversation.