Python String Snippets

The Python snippet collection contains helper functions for Python 3.6. It includes utilities for most common data types, such as primitivies, lists, dictionaries and date objects.

  • String is anagram

    Checks if a string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters).

    Python, String · Nov 2, 2020

  • Reverse list

    Reverses a list or a string.

    Python, List · Nov 2, 2020

  • How do I convert a string to lowercase in Python?

    Learn of the two different way to convert a string to lowercase in Python and understand when you should use each one with this quick guide.

    Python, String · Jun 12, 2021

  • How can I check if a string is empty in Python?

    Here are two quick and elegant ways to check if a string is empty in Python.

    Python, String · Aug 5, 2022

  • Pad string

    Pads a string on both sides with the specified character, if it's shorter than the specified length.

    Python, String · Oct 3, 2020

  • How do I trim whitespace from a string in Python?

    Oftentimes you might need to trim whitespace from a string in Python. Learn of three different way to do this in this short guide.

    Python, String · Dec 13, 2021

  • Palindrome

    Checks if the given string is a palindrome.

    Python, String · Nov 2, 2020

  • Pad number

    Pads a given number to the specified length.

    Python, String · Nov 2, 2020

  • Byte size of string

    Returns the length of a string in bytes.

    Python, String · Nov 2, 2020

  • Capitalize every word

    Capitalizes the first letter of every word in a string.

    Python, String · Nov 2, 2020

  • Repeat string

    Generates a string with the given string value repeated n number of times.

    Python, String · Nov 2, 2020