- 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 Suggested Problems
Print a matrix of 20 × 20 stars or asterisks (*). From within IDLE, demonstrate the slowest possible means of doing this task and the fastest possible means. (Hint: Does the fastest way utilize string concatenation of the join method?) Compare and contrast. Then use a decorator to profile the speeds of the two ways of printing the asterisks.
Write a generator to print all the perfect squares of integers, up to a specified limit. Then write a function to determine whether an integer argument is a perfect square if it falls into this sequence—that is, if n is an integer argument, the phrase n in square_iter(n) should yield True or False.