Pythonic Programming: Tips for Becoming an Idiomatic Python Programmer
- Length: 152 pages
- Edition: 1
- Language: English
- Publisher: Pragmatic Bookshelf
- Publication Date: 2021-10-19
- ISBN-10: 168050861X
- ISBN-13: 9781680508611
- Sales Rank: #466591 (See Top 100 Books)
Make your good Python code even better by following proven and effective pythonic programming tips. Avoid logical errors that usually go undetected by Python linters and code formatters, such as frequent data look-ups in long lists, improper use of local and global variables, and mishandled user input. Discover rare language features, like rational numbers, set comprehensions, counters, and pickling, that may boost your productivity. Discover how to apply general programming patterns, including caching, in your Python code. Become a better-than-average Python programmer, and develop self-documented, maintainable, easy-to-understand programs that are fast to run and hard to break.
Python is one of the most popular and rapidly growing modern programming languages. With more than 200 standard libraries and even more third-party libraries, it reaches into the software development areas as diverse as artificial intelligence, bioinformatics, natural language processing, and computer vision. Find out how to improve your understanding of the spirit of the language by using one hundred pythonic tips to make your code safer, faster, and better documented.
This programming style manual is a quick reference of helpful hints and a random source of inspiration. Choose the suitable data structures for searching and sorting jobs and become aware of how a wrong choice may cause your application to be completely ineffective. Understand global and local variables, class and instance attributes, and information-hiding techniques. Create functions with flexible interfaces. Manage intermediate computation results by caching them in files and memory to improve performance and reliability. Polish your documentation skills to make your code easy for other programmers to understand. As a bonus, discover Easter eggs cleverly planted in the standard library by its developers.
Polish, secure, and speed-up your Python applications, and make them easier to maintain by following pythonic programming tips.
What You Need:
You will need a Python interpreter (ideally, version 3.4 or above) and the standard Python library that usually comes with the interpreter.
Acknowledgments Preface Introduction About the Software About the Notation About the Reader 1. Documentation Tips Tip 1. Hello, World! Tip 2. Import This Tip 3. Know Ownership and Licensing Tip 4. Use Quotes of All Sorts Tip 5. Keep Letter Case Consistent Tip 6. Wrap Long Lines Tip 7. Self-Document Your Code Tip 8. Do Not Misuse Docstrings Tip 9. Let input() Speak for Itself Tip 10. Mark Dummy Variables Tip 11. Distinguish Parameters and Arguments Tip 12. Avoid “Magic” Values Tip 13. Enumerate Your Constants 2. General Tips Tip 14. Chain Comparison Operators Tip 15. Expand the Tabs Tip 16. Pickle It Tip 17. Avoid range() in Loops Tip 18. Pass It Tip 19. Try It Tip 20. Embrace Comprehensions Tip 21. Make Your Code Compact with Conditional Expressions Tip 22. Find the “Missing” Switch Tip 23. Eschew Comprehension Expressions, If Needed Tip 24. Use Slicing to Reverse and Split Tip 25. sum() Almost Anything Tip 26. Transpose with zip() Tip 27. Discover All Characters in One Place Tip 28. glob() the Files Tip 29. Use Strings as Files Tip 30. Pick to str() or to repr() Tip 31. Remember, input() Remembers Tip 32. Do Linear Algebra in Python 3. Data Types and Data Structures Tips Tip 33. Construct a One-Element Tuple Tip 34. Improve Readability with Raw Strings Tip 35. Unpack Lists and Tuples Tip 36. Print a List Tip 37. Flatten That List Tip 38. Treat Your Code as a Module Tip 39. Let Modules Act Independently Tip 40. Add Class Attributes Tip 41. Serialize Objects Tip 42. Count with defaultdict Tip 43. Count with Counter Tip 44. Explore How int() Supports Other Bases Tip 45. Discover Complex Numbers Tip 46. Rational Numbers Exist Tip 47. Discover an Infinity Tip 48. Carve It in Stone Tip 49. No Trees? Use a dict() 4. Function Tips Tip 50. Make Functions Always Return Something Tip 51. Return Consistently Tip 52. Let the Caller Print Tip 53. Return Many Values Tip 54. Understand Optional and Keyword Parameters Tip 55. Pass Arguments Your Way Tip 56. Omit Else After Return Tip 57. Chain Function Calls Tip 58. Yield, Do Not Return Tip 59. Return and Apply Functions Tip 60. Savvy Anonymous Functions 5. Performance Tips Tip 61. Time It Tip 62. Avoid Function Calls; They Are Costly Tip 63. Build, Then Print Tip 64. Format with Formatted Strings Tip 65. Import Wisely Tip 66. Import as Needed Tip 67. Optimize Lookups Tip 68. Cache It Tip 69. Checkpoint, It Saves Time Tip 70. Sort Big in Place Tip 71. Delete Your Garbage Tip 72. Beware of Large and Slow Ints Tip 73. Waste Space, Save Time Tip 74. Do Not str() a str 6. Safety Tips Tip 75. Call That Function Tip 76. Get the Hang of Local Variables Tip 77. Grasp What Is Truth Tip 78. Check for Range Tip 79. Strip User Input Tip 80. Let Python Close Your Files Tip 81. Read Files Safely Tip 82. Hide Everything Tip 83. Use Properties Tip 84. Compare One to Many Tip 85. Check, Then Touch Tip 86. Assert Conditions Tip 87. Do Not eval(); It Is Evil Tip 88. Parse with literal_eval() Tip 89. Treat Variables as References Tip 90. Isolate Exceptions Tip 91. Compare Prefixes and Suffixes Tip 92. Remember, There Are No Globals Tip 93. Is Is Not What You Think It Is Tip 94. Distinguish type() and isinstance() Tip 95. 50,000 Is Not a Number, but 50_000 Is Tip 96. Do Not Confuse Boolean and Bitwise Operators Tip 97. Do Not Call Your List “List” Tip 98. Do Not Change That Loop Variable Tip 99. str.split() by White Spaces Tip 100. Get over str.split() 7. Wrapping Up Bibliography
Donate to keep this site alive
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.