Editor settings

General settings

Save settings

Learn to program with Python

Create Your Str Class #

In these next lessons, we will learn to implement our own str class to get a better understanding of utilizing a class and common special methods in Python.

Let's take a look at how to create a string object from the str class:

sentence = str("Python is amazing!")

This is what we will try to mimic in this lesson. Let's not think too far ahead and start by implementing a very simple class here.


Exercise #

  • Define the __init__ method inside the class MyStr to mimic the behavior of the class str above.

Tests #

  • Create a new class named MyStr
  • MyStr("Python is amazing!") should create a new object
Output will be displayed here