Python programs you can run and test

Each page explains a common Python program a few ways, shows the output, and ends with a practice challenge from the PyMaster course. Python runs right in your browser, so you can edit and run every example.

Open the online Python compiler

  • How to remove duplicates from a list in Python

    Remove duplicates from a Python list and keep the original order, with dict.fromkeys, a set and a loop. Run every example in your browser.

  • Palindrome program in Python

    Check if a string or a number is a palindrome in Python with slicing, two pointers and a loop, and ignore spaces and case. Run every example in your browser.

  • Factorial program in Python

    Find the factorial of a number in Python with a for loop, recursion and math.factorial, including 0 and negative input. Run every example in your browser.

  • Fibonacci series in Python

    Print the Fibonacci series in Python with a for loop, a while loop, recursion and a generator, and find the nth Fibonacci number. Run every example in your browser.

  • Count how many times each character appears in a string in Python

    Count the frequency of each character in a Python string with a dict, collections.Counter and str.count, and find the most common one. Run it in your browser.