Python 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.

  • clamp_number

    Python, Math

    Clamps num within the inclusive range specified by the boundary values.

  • in_range

    Python, Math

    Checks if the given number falls within the given range.

  • pad_number

    Python, String

    Pads a given number to the specified length.

  • byte_size

    Python, String

    Returns the length of a string in bytes.

  • capitalize_every_word

    Python, String

    Capitalizes the first letter of every word in a string.

  • n_times_string

    Python, String

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

  • factorial

    Python, Math

    Calculates the factorial of a number.

  • Calculates the number of ways to choose k items from n items without repetition and without order.

  • degrees_to_rads

    Python, Math

    Converts an angle from degrees to radians.

  • rads_to_degrees

    Python, Math

    Converts an angle from radians to degrees.

  • to_binary

    Python, Math

    Returns the binary representation of the given number.

  • to_hex

    Python, Math

    Returns the hexadecimal representation of the given number.