Different meanings of brackets in Python

jake wong picture jake wong · Jun 8, 2015 · Viewed 84.2k times · Source

I am curious, what do the 3 different brackets mean in Python programming? Not sure if I'm correct about this, but please correct me if I'm wrong:

[] - # Normally used for dictionaries, list items
() - # Used to identify params
{} - # I have no idea what this does... 

Or if these brackets can be used for other purposes, any advice is welcomed! Thanks!

Answer

Maltysen picture Maltysen · Jun 8, 2015
  • []: Used to define mutable data types - lists, list comprehensions and for indexing/lookup/slicing.
  • (): Define tuples, order of operations, generator expressions, function calls and other syntax.
  • {}: The two hash table types - dictionaries and sets.