Fundamentals 13 min read

26 Must‑Know Python Tricks Every Developer Should Master

This article presents a curated A‑to‑Z collection of 26 practical Python tricks—from basic syntax shortcuts and standard‑library modules like collections and itertools to handy third‑party tools such as bashplotlib, geopy, and howdoi—designed to boost productivity and deepen your understanding of the language.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
26 Must‑Know Python Tricks Every Developer Should Master

Python is one of the most popular programming languages in the world.

Easy to learn

Cross‑platform

Huge ecosystem of modules and libraries

I use Python daily as a data scientist and have gathered a set of useful tips and tricks, presented here in an A‑to‑Z format.

bashplotlib

Want to plot charts in the console? Use bashplotlib to draw graphs directly in the terminal.

collections

The collections module extends Python’s built‑in data types with additional containers such as defaultdict, namedtuple, and Counter.

dir

Use the built‑in dir() function to inspect an object’s attributes. Example command line output shows the available methods and properties.

emoji

You can include emojis in your output; they work perfectly in the console.

from __future__ import

The __future__ module lets you import features from upcoming Python versions, effectively giving you a taste of future language capabilities.

geopy

The geopy library simplifies geocoding by providing a unified API to many services, allowing you to obtain addresses, latitude, longitude, altitude, and calculate distances with a convenient distance class.

howdoi

howdoi is a command‑line tool that fetches top StackOverflow answers without leaving the terminal, helping you quickly solve coding problems.

inspect

The inspect module can retrieve a function’s source code ( inspect.getsource()), its defining module ( inspect.getmodule()), and even its line number.

Jedi

The Jedi library provides auto‑completion and static analysis for Python code, useful for IDE plugins and projects like IPython.

**kwargs

**kwargs

allows a dictionary’s contents to be passed as named arguments to a function, enabling flexible APIs that accept arbitrary keyword parameters.

List comprehensions

List comprehensions let you create clean, readable lists in a single expression, often resembling natural language.

map

The built‑in map() function applies a function (often a lambda) to each element of an iterable, returning a map object that can be converted to a list or tuple.

newspaper3k

newspaper3k fetches articles and metadata from major news sites, including images, text, authors, and even provides basic NLP features.

Operator overloading

Python supports operator overloading, allowing custom classes to define special methods (e.g., __add__) that give objects the behavior of built‑in operators.

pprint

The pprint module pretty‑prints complex data structures, making nested objects easier to read.

queue

The queue module provides thread‑safe FIFO, LIFO, and priority queues, useful for multithreaded programming.

__repr__

Defining __repr__ in a class gives a helpful string representation of objects, aiding debugging.

sh

The sh library lets you call external programs as if they were regular Python functions, simplifying automation.

Type hints

Since Python 3.5 you can add optional type hints to functions and variables, improving readability and enabling static type checking.

uuid

The uuid module generates universally unique identifiers, producing 128‑bit random numbers with an astronomically low collision probability.

Virtual environments

Python’s venv (or virtualenv ) lets you isolate dependencies for multiple projects on the same machine.

wikipedia

The wikipedia module provides a convenient API to query Wikipedia, supporting multiple languages, disambiguation, random pages, and even a donate() method.

xkcd

Python is named after the webcomic xkcd , reflecting the language’s playful spirit.

YAML

YAML (YAML Ain’t Markup Language) is a superset of JSON. The PyYAML library lets you load and dump YAML data in Python.

zip

The built‑in zip() function aggregates elements from multiple iterables into tuples; using *zip() “unzips” them back.

Thank you for reading! You have now seen 26 Python tricks that can help you on your next project.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

automationprogramminglibrariesTips
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.