[' ' {' ' ' ' ' ' ' ' assigning new keys grows dictionaries [' 'error text omitted keyerror'freferencing nonexistent key is an error this is what we want--it' usually programming error to fetch something that isn' really there but in some generic programswe can' always know what keys will be present when we write our code how do we handle such cases and avoid errorsone solution is to test ahead of time the dictionary in membership expression allows us to query the existence of key and branch on the result with python if statement in the followingbe sure to press enter twice to run the if interactively after typing its code (as explained in an empty line means "goat the interactive prompt)and just as for the earlier multiline dictionaries and liststhe prompt changes to on some interfaces for lines two and beyond'fin false if not 'fin dprint('missing'python' sole selection statement missing this book has more to say about the if statement in later but the form we're using here is straightforwardit consists of the word iffollowed by an expression that is interpreted as true or false resultfollowed by block of code to run if the test is true in its full formthe if statement can also have an else clause for default caseand one or more elif ("else if"clauses for other tests it' the main selection statement tool in pythonalong with both its ternary if/else expression cousin (which we'll meet in momentand the if comprehension filter lookalike we saw earlierit' the way we code the logic of choices and decisions in our scripts if you've used some other programming languages in the pastyou might be wondering how python knows when the if statement ends 'll explain python' syntax rules in depth in later but in shortif you have more than one action to run in statement blockyou simply indent all their statements the same way--this both promotes readable code and reduces the number of characters you have to typeif not 'fin dprint('missing'print('noreally 'statement blocks are indented missing noreally dictionaries