PYTHON CORE · LESSON 48

Your type of data

Class and object · about 13 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

Class - drawing

The class describes what the object will be. For example, every cat can have a name.

class Cat:
    name = "Мур"
From drawing to subject
Class classCatCreationCat()Objectpet

✦ Cat is the name of a new type; the name lies within the class.

STEP 2

Create an object.

Cat() creates a cat by drawing. You can see his name through the dot.

pet = Cat()
print(pet.name)

✦ If the class from the first step is already created, you will see «Мур».

IN-CLASS PRACTICE

Type the code yourself

Take a small class and create an object.

class Dog:
    name = "Рекс"
pet = Dog()
print(pet.name)
Open the editor for class work
HOMEWORK

Solve it yourself

Create a Cat class with the property name = «Мур». Create pet with Cat() and output pet.name.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework