Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.