Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python (retired) Inheritance Score Method

Justin Noor
Justin Noor
3,692 Points

What are the bracket for in self.current_score = [0, 0] ?

I got this to work but never fully understood what the brackets are for in the self.current_score = [0, 0] line.

game.py
class Game:
  def __init__(self):
    self.current_score = [0, 0]

If I'm looking at this right, it looks as thogh self.current_score is an array that contains the scores for both player one and player two. The brackets denote that data stored is an array.

2 Answers

Andrew Smith
Andrew Smith
10,947 Points

The brackets create a list. The first item in the list tracks Player 1's score while the second track's Player 2's score. The method you are asked to create takes the argument which tells you which player scored and you increase either the first or second item in the list based on that argument.

The brackets is a list that hold default values. Each player starts with a score of 0.