Loading video player…

Course Intro & Example Python Class

This lesson will show you why you would want to control how a Python class is represented. In the lesson, you’ll create a Python class and see what happens when you try to print out one of its instances to the console. The result of doing this is relatively unsatisfying.

Avatar image for Cedric Liu

Cedric Liu on July 30, 2020

Why is the return value here shows console instead of main?

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on Aug. 3, 2020

It’s a quirk of bpython, which is an alternative Python interpreter that Dan’s using. In addition to this, he must have had executed a module called “console.py” in an interactive mode:

$ bpython -i console.py 

The default string representation of a user-defined class is prefixed with the name of a module it was defined in.

Become a Member to join the conversation.