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 Advanced Objects Subclassing Built-ins

self[item] notation

I don't understand why we use the '[' brackets instead of the traditional one: '('. Anyone able to clarify it?

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Stefano,

Brackets [] and parentheses () are used for completely different things in Python. There's also braces {}, which I won't get into, but those are used for other, completely different things.

In this video, Kenneth is using brackets because that's how you create slices. You may wish to review the section of the Python Collections course that covers slices. As a general rule, brackets are used when dealing with Python lists, or other iterables like strings (note slices are only applicable to iterables, hence the brackets). Parentheses are used for a number of things, but most notably defining and calling functions and types. They're also used to group mathematical operations - like (2 + 5) * 12, and grouping import statements and long if statements.

Hope that's helpful!

Cheers :beers:

-Greg