Back to Freecodecamp

Objects: A Sample Class

curriculum/challenges/english/blocks/python-for-everybody/5e7b9f160b6c005b0e76f086.md

latest369 B
Original Source

--questions--

--text--

What will the following program print?:

python
class PartyAnimal:
    x = 0
    def party(self):
        self.x = self.x + 2
        print(self.x)

an = PartyAnimal()
an.party()
an.party()

--answers--

<pre> So far 1 So far 2 </pre>
<pre> 0 0 </pre>
<pre> 2 2 </pre>
<pre> 2 4 </pre>

--video-solution--

4