About This Title

Pages: 130
Published: October 2021
ISBN: 9781680508611
Edition: 1
In Beta

Skill Level Meter

Pythonic Programming

Tips for Becoming an Idiomatic Python Programmer

by Dmitry Zinoviev

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.

eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $18.95 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal

This book is in Beta, final version expected Oct 2021

Beta Books: What do I get?


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.

Resources

Releases:

  • B1.0 2021/07/12

Contents & Extracts

Note: Contents and extracts of beta books will change as the book is developed.

  • Preface
  • Introduction
    • About the Software
    • About the Notation
    • About the Reader
  • Documentation Tips
    • Hello, World!
    • Import This
    • Know Ownership and Licensing
    • Use Quotes of All Sorts
    • Keep Letter Case Consistent
    • Wrap Long Lines
    • Self-Document Your Code
    • Do Not Misuse Docstrings
    • Let input() Speak for Itself
    • Mark Dummy Variables
    • Distinguish Parameters and Arguments
    • Avoid ``Magic’’ Values
    • Enumerate Your Constants
  • General Tips excerpt
    • Chain Comparison Operators
    • Expand the Tabs
    • Pickle It
    • Avoid range() in Loops
    • Pass It
    • Try It
    • Embrace Comprehensions
    • Make Your Code Compact with Conditional Expressions
    • Find the ``Missing’’ Switch
    • Eschew Comprehension Expressions, If Needed
    • Use Slicing to Reverse and Split
    • sum() Almost Anything
    • Transpose with zip()
    • Discover All Characters in One Place
    • glob() the Files
    • Use Strings as Files
    • Pick to str() or to repr()
    • Remember, input() Remembers
    • Do Linear Algebra in Python
  • Data Types and Data Structures Tips excerpt
    • Construct a One-Element Tuple
    • Improve Readability with Raw Strings
    • Unpack Lists and Tuples
    • Print a List
    • Flatten That List
    • Treat Your Code as a Module
    • Let Modules Act Independently
    • Add Class Attributes
    • Serialize Objects
    • Count with defaultdict
    • Count with Counter
    • Explore How int() Supports Other Bases
    • Discover Complex Numbers
    • Rational Numbers Exist
    • Discover an Infinity
    • Carve It in Stone
    • No Trees? Use a dict()
  • Function Tips
    • Make Functions Always Return Something
    • Return Consistently
    • Let the Caller Print
    • Return Many Values
    • Understand Optional and Keyword Parameters
    • Pass Arguments Your Way
    • Omit Else After Return
    • Chain Function Calls
    • Yield, Do Not Return
    • Return and Apply Functions
    • Savvy Anonymous Functions
  • Performance Tips
    • Time It
    • Avoid Function Calls; They Are Costly
    • Build, Then Print
    • Format with Formatted Strings
    • Import Wisely
    • Import as Needed
    • Optimize Lookups
    • Cache It
    • Checkpoint, It Saves Time
    • Sort Big in Place
    • Delete Your Garbage
    • Beware of Large and Slow Ints
    • Waste Space, Save Time
    • Do Not str() a str
  • Safety Tips excerpt
    • Call That Function
    • Get the Hang of Local Variables
    • Grasp What Is Truth
    • Check for Range
    • Strip User Input
    • Let Python Close Your Files
    • Read Files Safely
    • Hide Everything
    • Use Properties
    • Compare One to Many
    • Check, Then Touch
    • Assert Conditions
    • Do Not eval(), It Is Evil
    • Parse with literal_eval()
    • Treat Variables as References
    • Isolate Exceptions
    • Compare Prefixes and Suffixes
    • Remember, There Are No Globals
    • Is Is Not What You Think It Is
    • Distinguish type() and isinstance()
    • 50,000 Is Not a Number, but 50_000 Is
    • Do Not Confuse Boolean and Bitwise Operators
    • Do Not Call Your List ``List’’
    • Do Not Change That Loop Variable
    • str.split() by White Spaces
    • Get over str.split()
  • Wrapping Up

Author

Dmitry Zinoviev is a professor of Computer Science at Suffolk University in Boston and has a dual degree in Physics and Computer Science. He is passionate about C and Python programming, complex network analysis, computational social science, and digital humanities.

eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $18.95 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal

This book is in Beta, final version expected Oct 2021

Beta Books: What do I get?

Related Titles:

Skill Level Meter

About This Title

Pages: 130
Published: October 2021
ISBN: 9781680508611
Edition: 1
In Beta