Home > Articles

  • Print
  • + Share This
This chapter is from the book

Chapter 4 Questions for Review

  1. Is an assignment operator such as += only a convenience? Can it actually result in faster performance at run time?

  2. In most computer languages, what is the minimum number of statements you’d need to write instead of the Python statement a, b = a + b, a?

  3. What’s the most efficient way to initialize a list of 100 integers to 0 in Python?

  4. What’s the most efficient way of initializing a list of 99 integers with the pattern 1, 2, 3 repeated? Show precisely how to do that, if possible.

  5. If you’re running a Python program from within IDLE, describe how to most efficiently print a multidimensional list.

  6. Can you use list comprehension on a string? If so, how?

  7. How can you get help on a user-written Python program from the command line? From within IDLE?

  8. Functions are said to be “first-class objects” in Python but not in most other languages, such as C++ or Java. What is something you can do with a Python function (callable object) that you cannot do in C or C++?

  9. What’s the difference between a wrapper, a wrapped function, and a decorator?

  10. When a function is a generator function, what does it return, if anything?

  11. From the standpoint of the Python language, what is the one change that needs to be made to a function to turn it into a generator function?

  12. Name at least one advantage of generators.

  • + Share This
  • 🔖 Save To Your Account