Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Mastering Method Types With the OOP Pizza Example

In this lesson you’ll write a basic Pizza class, which is later used to demonstrate some use cases for the different method types.

Steven Rowland on June 12, 2019

You need fresh basil on a Margarita pizza. And cheese? What kind of cheese? These are important details. You need a pizza validator.

Dan Bader RP Team on June 12, 2019

@Steven: Haha, all good points… time to work on a course on attribute validation :-)

Dan Bader RP Team on June 12, 2019

Just got this comment via the feedback form and I wanted to share it here because it raises a good point:

One thing that got my eyes on was how ingredient parameter is used in the constructor. This parameter is given in as a sequence argument (list) and for that reason it should be stored to the instance variable by copying it.

self.ingredients = list(ingredients)

Not particularly relevant to this tutorial but anyway might this may lead to an unexpected situations. At least novice python programmer’s should be aware of.

Lastly, I want to say thanks for the awesome site Real Python! I have used Python for years and still I constantly learn new things from the site. Real Python certainly has raised my Python knowledge yet to another level.

I agree it would be good to make a copy of the ingredients list when assigning it to the instance variable, so thanks for that. Potentially we might event want to do a deep copy here.

balakumaranrk on Feb. 9, 2020

can please you explain in detail what the method def repr(self) is used for ?

Dan Bader RP Team on Feb. 9, 2020

Check out this video course as a follow up: Pythonic OOP String Conversion: __repr__ vs __str__

Become a Member to join the conversation.