- Python Shortcuts, Commands, and Packages
- 4.2 Twenty-Two Programming Shortcuts
- 4.3 Running Python from the Command Line
- 4.4 Writing and Using Doc Strings
- 4.5 Importing Packages
- 4.6 A Guided Tour of Python Packages
- 4.7 Functions as First-Class Objects
- 4.8 Variable-Length Argument Lists
- 4.9 Decorators and Function Profilers
- 4.10 Generators
- 4.11 Accessing Command-Line Arguments
- Chapter 4 Summary
- Chapter 4 Questions for Review
- Chapter 4 Suggested Problems
Chapter 4 Questions for Review
Is an assignment operator such as += only a convenience? Can it actually result in faster performance at run time?
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?
What’s the most efficient way to initialize a list of 100 integers to 0 in Python?
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.
If you’re running a Python program from within IDLE, describe how to most efficiently print a multidimensional list.
Can you use list comprehension on a string? If so, how?
How can you get help on a user-written Python program from the command line? From within IDLE?
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++?
What’s the difference between a wrapper, a wrapped function, and a decorator?
When a function is a generator function, what does it return, if anything?
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?
Name at least one advantage of generators.