Python tricks

A buffet of awesome python features


15 Jul 2018 View Comments
#bookreview #python #software #computer #programming

Python Tricks

My Overall Rating:

I have read a couple of Python books so far, including Python Crash Course and Python Cookbook. These books mainly focus on showing how primitive types and basic data structures are applied in Python. When I first got introduced to Dan Bader’s Python Tricks: The Book by a colleague of mine, I just bought the book based on my colleague’s involvement in Python language. I really had no clue how good the contents and materials are. After finish reading the book, I am glad I had an opportunity of reading. Although the book is just below 300 pages long, it is probably one of the books where I have the most noted items.

When I first bought the book, I wasn’t really interested in learning Python at all. The language didn’t appeal to me as I was really into Java most of the time. Coming from Perl background, I didn’t feel like learning another scripting language. However, as my company had a lot of software written in Python, it was inevitable for me to obtain a good comprehensive knowledge of Python. After reading a couple of Python books, I started yearning to broaden my understanding of Python. That’s when I realized that I had this book I bought last year sitting on my shelf.

The first edition of the book was published in October 2017 which is one of a few things I like about the book. The book is quite new and it contains a lot of new Python syntax and patterns. It also talks mostly about Python 3.6 (3.7 is just out last month). For your information, Python has been in the market for a long time and the author who alleges to have 10 years of experiences in Python surely understands what’s going on and how to relay that knowledge as easy as possible.

Reading this book reminisced of reading “Effective Java” where it explains ways of handling Java things. This book (Python Tricks) would instead give Pythonic ways of handling things in a simplified, precise and efficient way. There are some important things mentioned in the book about Pythonic ways/patterns of coding, how functions are basically an object in Python, Data structures used in Python, how classes are used in Python, etc. Here are some important topics discussed in the book in a point form:

Patterns

  • Use Assertion
  • Context manager + “with” Statment
  • Underscores + dunders
  • String formatting

Functions

  • Functions are Objects which can be stored in variables, data structures and can be passed to other functions, can be nested
  • Lambdas: small anonymous function
  • Decorator
  • *args vs **kwargs (argument packing)

Classes & OOP

  • “is” vs “==”
  • str vs repl
  • cloning
  • instance, classmethod, staticmethod

Data structures

  • dictionary, maps, hash tables
  • array, list
  • sets, multisets
  • stacks, queues, priority queues

Rest

  • loops (syntactic sugar) - for-in, enumerate, items, range
  • slicing, generators, iterators
  • dictionary tricks
  • environments
Share this post

Me

I am a passionate software developer working in Downtown, Vancouver. I strongly believe in art of algorithms and together with it to write clean and efficient software to build awesome products. If you would like to connect with me, choose one from below options :) You can also send me an email at