...

/

Puzzle 1: Explanation

Puzzle 1: Explanation

Let’s find out how attribute lookup works in Python.

Let’s try it!

Try executing the code below to verify the results:

Press + to interact
class Player:
# Number of players in the Game
count = 0
def __init__(self, name):
self.name = name
self.count += 1
p1 = Player('Parzival')
print(Player.count)

Code explanation

When we write self.count, we’re doing an attribute lookup. The attribute that we’re looking for in this case is count. Getting ...

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy