## 3.26 Why are colons required for the if/while/def/class state- ments? 

The colon is required primarily to enhance readability (one of the results of the experimental ABC language). Con- sider this: 

if a ==b print(a) 

versus 

if a ==b: print(a) 

Notice how the second one is slightly easier to read. Notice further how a colon sets off the example in this FAQ answer; it’s a standard usage in English. 

Another minor reason is that the colon makes it easier for editors with syntax highlighting; they can look for colons to decide when indentation needs to be increased instead of having to do a more elaborate parsing of the program text. 

## 3.27 Why does Python allow commas at the end of lists and tu- ples? 

Python lets you add a trailing comma at the end of lists, tuples, and dictionaries: 

[1,2,3,] ('a','b','c',) d ={ "A": [1,5], "B": [6,7], # last trailing comma is optional but good style } 

There are several reasons to allow this. 

When you have a literal value for a list, tuple, or dictionary spread across multiple lines, it’s easier to add more elements because you don’t have to remember to add a comma to the previous line. The lines can also be reordered without creating a syntax error. 

Accidentally omitting the comma can lead to errors that are hard to diagnose. For example: 

x =[ "fee", "fie" "foo", "fum" ] 

This list looks like it has four elements, but it actually contains three: “fee”, “fiefoo” and “fum”. Always adding the comma avoids this source of error. 

Allowing the trailing comma may also make programmatic code generation easier. 

