Return to home page

Python Quiz: Module 5

List of Dictionaries


  1. Which of the following code snippets describe an ordered collection of data in Python?

  2. Which of the following words is used to describe a collection?

  3. Which code snipped can be used to access the letter s from a variable named level referencing the string basic?

  4. What is the value of the variable output after running this code output = '1,2,3'.split(',')?

  5. If you have a tupple named colors which contains ('white','red','green'), how do you access the color red from the tupple?

  6. The following code describes the assignment of a dictionary to a variable: my_dict = {'day':'Tuesday','weather':'snow','temp':'32F'}. Which of the code snippets below can be used to convert the dictionary into 3 string variables: day_of_week,precipitation,temperature?

  7. After opening a CSV file with read mode, you read the data one row at time with for row in file.readlines():. You want to convert each row from a csv string terminated by a newline into a list of strings. Which code snippet can you use to convert the row from a string with a newline into a list of data strings.

  8. If you want raise an exception when a user has chosen option 5, but you only support options 1-4, how will you code this?

  9. When will the code following except FileNotFoundError as e: be executed?

  10. What is the purpose of finally in Python exception handling?