Locked learning resources

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

Unlock This Lesson

Locked learning resources

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

Unlock This Lesson

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.

Avatar image for Steven Rowland

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.

Avatar image for Dan Bader

Dan Bader RP Team on June 12, 2019

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

Avatar image for Dan Bader

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.

Avatar image for balakumaranrk

balakumaranrk on Feb. 9, 2020

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

Avatar image for Dan Bader

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.