Skip to main content
  • Python is available now. All other compilers are coming soon.

    Python
  • Popular Tutorials

    • Getting Started With Python
    • Python if Statement
    • while Loop in Python
    • Python Lists
    • Dictionaries in Python
    All Python Tutorials

    Reference Materials

    Built-in FunctionsList MethodsDictionary MethodsString Methods
    View all

Online Compilers

  • Python Compiler
  • Python Playground
  • Python Projects
  • Exercises

Tutorials

  • Learn Python
  • Python for Beginners
  • Variables and Types
  • Python Strings
  • Python Lists
  • Python If Else
  • Python For Loops
  • Python Functions
  • Python Classes

Examples

  • Python Examples
  • Hello World
  • Add Two Numbers
  • Even or Odd
  • Factorial
  • Fibonacci
  • Prime Check
  • Palindrome Check

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Use
  • Disclaimer

© 2026 ILoveCompiler. All rights reserved.

  1. Home
  2. Python Examples

Verified example programs

Python examples you can run

Short, complete programs that show one idea at a time. Each example includes the code, the exact output, and an explanation you can read before or after running it.

Open the compilerTry an exercise

Examples

30

Categories

16

Runs locally

In your browser

Categories

  1. Basic Programs1
  2. Variables2
  3. Operators2
  4. Conditional Statements4
  5. Loops4
  6. Functions1
  7. Strings3
  8. Lists2
  9. Tuples1
  10. Dictionaries1
  11. Sets1
  12. Mathematical Programs2
  13. Number Programs2
  14. Pattern Programs2
  15. File Handling1
  16. OOP1

Basic Programs

1 example
beginner

Hello World in Python

The classic first program: print a greeting and a second line of text.

print · strings

Variables

2 examples
beginner

Add Two Numbers

Store two integers in variables and print their sum with an f-string.

variables · integers
beginner

Variables and Data Types

Create strings, integers, floats, and booleans, then inspect each type.

types · type()

Operators

2 examples
beginner

Calculate Simple Interest

Use arithmetic operators and formatted floats to compute interest.

arithmetic · float formatting
beginner

Celsius to Fahrenheit

Convert a temperature with a formula and formatted output.

conversion · arithmetic

Conditional Statements

4 examples
beginner

Even or Odd Checker

Use the modulo operator and an if-else statement to classify an integer.

if else · modulo
beginner

Find the Largest of Three Numbers

Combine conditions with and to find the maximum of three values.

if elif · comparisons
beginner

Check a Leap Year

Combine divisibility rules to decide whether a year is a leap year.

conditions · calendar
beginner

Grade Calculator

Map a numeric score to a letter grade using an if-elif ladder.

if elif · ranges

Loops

4 examples
beginner

Multiplication Table

Print a ten-row multiplication table with a for loop and range().

for loop · range
beginner

Calculate a Factorial

Multiply numbers in a loop to compute n! with a loop.

for loop · accumulator
beginner

Fibonacci Series

Generate the first n Fibonacci numbers with parallel assignment.

loops · sequences
beginner

Sum of Natural Numbers

Add the first n natural numbers with a loop and compare the closed formula.

loops · sum

Functions

1 example
beginner

A Function with a Default Argument

Define a reusable greeting function with a default parameter value.

functions · parameters

Strings

3 examples
beginner

Palindrome Checker

Normalize a phrase and compare it with its reverse to detect a palindrome.

strings · slicing
beginner

Count Vowels

Count the vowels in a sentence with a loop and a membership test.

strings · loops
beginner

Capitalize Each Word

Transform a sentence with the title() string method.

strings · title case

Lists

2 examples
beginner

List Statistics

Compute count, sum, minimum, maximum, and average for a list of numbers.

lists · statistics
intermediate

Remove Duplicates while Preserving Order

Use dictionary keys to deduplicate a list without losing the original order.

lists · dictionaries

Tuples

1 example
beginner

Tuple Unpacking

Unpack a coordinate tuple and calculate its distance from the origin.

tuples · unpacking

Dictionaries

1 example
intermediate

Word Frequency Counter

Count repeated words with a dictionary and print the results in alphabetical order.

dictionaries · counting

Sets

1 example
beginner

Set Operations

Compare two skill sets with union, intersection, and difference.

sets · union

Mathematical Programs

2 examples
beginner

Area and Circumference of a Circle

Import the math module and use pi to calculate circle measurements.

math · pi
intermediate

Quadratic Equation Roots

Use the quadratic formula and math.sqrt to find real roots.

math · formula

Number Programs

2 examples
intermediate

Prime Number Checker

Test divisibility up to the square root of a number for an efficient prime check.

prime numbers · loops
beginner

Reverse a Number

Reverse the digits of an integer by converting it to a string.

strings · integers

Pattern Programs

2 examples
beginner

Star Pyramid Pattern

Use spaces and string repetition to print a centred star pyramid.

patterns · loops
beginner

Floyd's Triangle

Print a right-angled triangle of consecutive natural numbers.

patterns · nested loops

File Handling

1 example
intermediate

Write and Read a Text File

Create a file in Python's virtual filesystem, then read it back.

files · with

OOP

1 example
intermediate

Bank Account Class

Model a bank account with a class, methods, and simple validation.

classes · objects