Curly Braces/Brackets


Just out of curiosity, is there a specific reason as to why the curly braces/brackets are on separate lines and are not indented? As opposed to being in front of "banana" on the second line and after "pear":3 on the fifth line.

prices= {


The { has to be on the same line as prices = because it is an opening bracket, and part of the variable definition. However, this code could just as easily be written like this:

prices = {"banana": 4, "apple": 2, "orange": 1.5, "pear": 3}

It is most likely written the way it is for aesthetic purposes. Many programmers will use a vertical layout when defining dictionaries, arrays, or lists when they have a lot of data to add to them.


Oh ok, thank you so much!


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