bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Python/Object-Oriented Python
Python•Object-Oriented Python

Python Classes and Objects

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Python Classes and Objects?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ MyClass:
3Order

Put the learning moves in the order that makes the concept easiest to apply.

Python is an object oriented programming language.
The pass Statement
Python Classes/Objects

Python Classes/Objects

Python is an object oriented programming language.

Almost everything in Python is an object, with its properties and methods.

A Class is like an object constructor, or a "blueprint" for creating objects.

Create a Class

To create a class, use the keyword class :

Example

class MyClass:
  x = 5

Create Object

Now we can use the class named MyClass to create objects:

Example

p1 = MyClass()
print(p1.x)

Delete Objects

You can delete objects by using the del keyword:

del p1

Multiple Objects

You can create multiple objects from the same class:

Example

p1 = MyClass()
p2 = MyClass()
p3 = MyClass()
print(p1.x)
print(p2.x)
print(p3.x)

Note

Each object is independent and has its own copy of the class properties.

The pass Statement

class definitions cannot be empty, but if you for some reason have a class definition with no content, put in the pass statement to avoid getting an error.

Example

class Person:
  pass

Previous

Python OOP

Next

Python __init__() Method