The Teclado Blog
  • Start Learning Python
  • Courses

Python Snippets

A collection of 27 posts

All Posts • Coding Interview Problems • Flask • GUI Development • Learn Python Programming • Python Snippets • REST APIs • Understanding the Console • Web Development
Assignment expressions in Python
Python Snippets

Assignment expressions in Python

Learn about Python's new assignment expression syntax and walrus operator. Assignment expressions can cut down on boilerplate code and improve efficiency!

    Phil Best
    4 min read · Oct 21
Python's namedtuples
Python Snippets

Python's namedtuples

Learn how to use the collection module's namedtuples to make your Python code even more clear and readable!

    Phil Best
    3 min read · Oct 14
Python's divmod Function
Python Snippets

Python's divmod Function

Learn all about Python's divmod function, which allows us to easily perform floor division and modulo operations in one go!

    Phil Best
    3 min read · Oct 7
Python's format Function
Python Snippets

Python's format Function

You may be familiar with Python's format method, but what about the format function? Learn to use Python's formatting language without string interpolation!

    Phil Best
    2 min read · Sep 30
Python's Partition Method for Strings
Python Snippets

Python's Partition Method for Strings

In this post we cover a lesser known string method called partition. It has a lot of similarities to split, but there are some interesting differences.

    Phil Best
    2 min read · Sep 23
Formatting Integers in Different Bases in Python
Python Snippets

Formatting Integers in Different Bases in Python

In this post we dive deeper into Python's formatting syntax, learning about displaying numbers in different bases. We also make a neat colour converter too!

    Phil Best
    3 min read · Sep 16
Nested String Interpolation in Python
Python Snippets

Nested String Interpolation in Python

In this post we continue looking at formatting, this time exploring nested string interpolation, which we can use to dynamically set formatting options.

    Phil Best
    3 min read · Sep 9
Formatting Numbers for Printing in Python
Python Snippets

Formatting Numbers for Printing in Python

Learn how to leverage Python's detailed formatting language to control how numbers are displayed in your applications.

    Phil Best
    3 min read · Sep 2
Python's "Ternary Operator"
Python Snippets

Python's "Ternary Operator"

Learn about conditional statements in Python: a slightly obscure bit of syntax that allows for succinct conditional logic, particularly during assignments.

    Phil Best
    2 min read · Aug 26
Generating a Collection of Random Numbers in Python
Python Snippets

Generating a Collection of Random Numbers in Python

In this post we learn about choices and sample: two useful functions in the random module used for generating collections of random values.

    Phil Best
    2 min read · Aug 19
Updating Python Dictionaries
Python Snippets

Updating Python Dictionaries

In this snippet post we look at the update method for dictionaries. We can use update to change several values at once or extend dictionaries with new keys.

    Phil Best
    2 min read · Aug 12
Extending Python Lists
Python Snippets

Extending Python Lists

In this week's Python snippet post we look at the extend method for lists. Extend works a lot like append, but allows us to append many values at once.

    Phil Best
    1 min read · Aug 5
Python Dictionaries and Loops
Python Snippets

Python Dictionaries and Loops

In this post we cover various ways we can iterate over dictionaries. Learn how to use the items and values methods to write more Pythonic loops with dicts.

    Phil Best
    1 min read · Jul 29
Python's zip_longest Function
Python Snippets

Python's zip_longest Function

zip is an incredibly powerful tool, but it has its limitations. Learn about zip_longest so you can zip collections of any length without losing data!

    Phil Best
    2 min read · Jul 22
Using zip in Python
Python Snippets

Using zip in Python

Python's zip function is extremely powerful and can simplify your code greatly, particularly when working with multiple iterables at the same time. In this post we cover a few ways to use it!

    Phil Best
    2 min read · Jul 15
A Closer Look at Python's Print Function
Python Snippets

A Closer Look at Python's Print Function

Print is one of the first functions we encounter when learning Python, but it can do a lot more than say "Hello, world!". Learn about print's other options and master this common function!

    Phil Best
    2 min read · Jul 8
Python Easter Eggs
Python Snippets

Python Easter Eggs

This week we take a look at some of Python's hidden Easter eggs, including perhaps the most important module in all of Python: antigravity.

    Phil Best
    2 min read · Jul 1
Python Deques
Python Snippets

Python Deques

Deques are a very handy collection type from the built-in "collections" module. They extend the functionality of lists and give us a couple more useful methods. Learn about them in this post!

    Phil Best
    2 min read · Jun 24
Python Itertools Part 2 - Combinations & Permutations
Python Snippets

Python Itertools Part 2 - Combinations & Permutations

This week we continue our look at the itertools module, this time covering the permutations and combinations functions.

    Phil Best
    2 min read · Jun 17
Python Itertools Part 1 - Product
Python Snippets

Python Itertools Part 1 - Product

The itertools module contains a bunch of handy functions. Here we take a look at product, which can serve as a replacement for complex comprehensions.

    Phil Best
    3 min read · Jun 10
Python's symmetric_difference Method for Sets
Python Snippets

Python's symmetric_difference Method for Sets

In this Python snippet post we cover a lesser known set method: symmetric_difference.

    Phil Best
    1 min read · Jun 3
Python Comprehensions with Conditionals
Python Snippets

Python Comprehensions with Conditionals

In this snippet post we show you how to add conditional clauses to your list comprehensions. Once you know how to use it, this kind of filtering is very powerful.

    Phil Best
    2 min read · May 27
List Comprehensions in Python
Python Snippets

List Comprehensions in Python

Learn how to use Python's list comprehension syntax: an awesome, Pythonic tool for creating new lists from existing iterables.

    Phil Best
    1 min read · May 20
Python's Enumerate Function
Python Snippets

Python's Enumerate Function

In this Python snippet post we take a look at the enumerate function: a vital tool for creating Pythonic loops.

    Phil Best
    1 min read · May 13
Python Set Operators
Python Snippets

Python Set Operators

In this post we cover shorthand operators for performing set operations in Python. We'll look at the three most common ones: union, intersection, and difference.

    Phil Best
    1 min read · May 6
The Teclado Blog © 2025
Privacy Policy