csev / py4e

Web site for www.py4e.com and source to the Python 3.0 textbook
http://www.py4e.com
2.88k stars 1.78k forks source link

Chapter 14#Different results of Multiple instances from the text #206

Closed joilo closed 10 months ago

joilo commented 5 years ago

Hi, I am Jess who is a newbie of Python.

In the Multiple instances part of Chapter 14: Python Objects, I run the code given in the online text book but find that the result on my computer is different from that given in the book.

I'm wondering whether it is an error or there're other reasons for that? Here's the code: class PartyAnimal: x = 0 name = '' def init(self, nam): self.name = nam print(self.name,'constructed')

def party(self) : self.x = self.x + 1 print(self.name,'party count',self.x)

s = PartyAnimal('Sally') j = PartyAnimal('Jim')

s.party() j.party() s.party()

Code: http://www.py4e.com/code3/party5.py

Here's my result: Sally constructed Jim constructed Sally party count 1 Jim party count 1 Sally party count 2

And Here's the result on the book: Sally constructed Sally party count 1 Jim constructed Jim party count 1 Sally party count 2

https://www.py4e.com/html3/14-objects

I'm sorry for paying your attention, if someone already reported this issue.

csev commented 10 months ago

There was definitely some confusion between the book, slides and lectures in Chapter 8. I redid the book, PowerPoint and lectures - so think this has been addressed. Please take a look at

https://www.py4e.com/lessons/Objects

Let me know if this has not been fixed by opening a new issue.