Curly and square brackets


#1

First we create two dictionaries with curly brackets. But why we use square brackets in the loop after that (and not the curly ones)?

Here’s the code:

prices = {
  "banana" : 4,
  "apple"  : 2,
  "orange" : 1.5,
  "pear"   : 3,
}
stock = {
  "banana" : 6,
  "apple"  : 0,
  "orange" : 32,
  "pear"   : 15,
}

for key in prices:
  print key
  print "price: %s" % prices[key]
  print "stock: %s" % stock[key]

#2

Curly brackets denote a dictionary, or set. Square brackets denote a subscript such as an index or key name.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.