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

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds 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.

Comments & Discussion

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.

Become a Member to join the conversation.