Utility Programs and Miscellaneous Examples

Key Takeaway: Practice Python with 110+ runnable examples covering strings, lists, dicts, math, dates, OOP, and file I/O — complete with expected terminal outputs.

Audience & Use Case: Designed for computer science students, data analysts, backend developers, and job seekers preparing for Python technical interviews.

Last updated: October 2026 110 Verified Examples

Quick Start & How to Use

  1. Select a Python example topic from the sidebar menu (or mobile dropdown).
  2. Examine the structured source code and corresponding expected output.
  3. Copy code directly or test it in our Online Python Compiler.
  4. Experiment by tweaking variables, loops, and conditions to deepen your understanding.

Who is this for: Beginners, interview candidates, and developers looking for reliable code snippets.

Credible Resources:Python Tutorial · Python Compiler · Python 3 Official Documentation · JavaScript Examples

Python Program to Check If Two Strings are Anagram

Compares sorted letters.

Source Code
def anagram(a,b):
    return sorted(a.replace(' ','').lower()) == sorted(b.replace(' ','').lower())
print(anagram('listen','silent'))
Expected Output
True

Python Program to Shuffle Deck of Cards

Shuffles deck deterministically.

Source Code
import random
random.seed(0)
suits = ['H','D','C','S']
ranks = ['A','2','3','4','5','6','7','8','9','10','J','Q','K']
deck = [r+s for s in suits for r in ranks]
random.shuffle(deck)
print(deck[:5])
Expected Output
['7C', '5H', 'QD', '2S', '3D']

Python Program to Display Calendar

Shows month calendar.

Source Code
import calendar
print(calendar.month(2025, 1))
Expected Output
    January 2025
Mo Tu We Th Fr Sa Su
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

Python Program to Merge Mails

Simple mail merge.

Source Code
names = ['Ann','Bob']
template = 'Hello {name}, welcome.'
msgs = [template.format(name=n) for n in names]
print('\n'.join(msgs))
Expected Output
Hello Ann, welcome.
Hello Bob, welcome.

Python Program to Find the Size (Resolution) of an Image

Uses Pillow for image size.

Source Code
from PIL import Image
img = Image.new('RGB', (640, 480))
print(img.size)
Expected Output
(640, 480)

Python Program to Merge Two Dictionaries

Merges using unpack.

Source Code
a = {'x':1}
b = {'y':2}
c = {**a, **b}
print(c)
Expected Output
{'x': 1, 'y': 2}

Python Program to Access Index of a List Using for Loop

Uses enumerate.

Source Code
lst = ['a','b','c']
for i, v in enumerate(lst):
    print(i, v)
Expected Output
0 a
1 b
2 c

Python Program to Split a List Into Evenly Sized Chunks

Chunking utility.

Source Code
def chunks(lst, n):
    return [lst[i:i+n] for i in range(0, len(lst), n)]
print(chunks([1,2,3,4,5], 2))
Expected Output
[[1, 2], [3, 4], [5]]

Python Program to Parse a String to a Float or Int

Converts string.

Source Code
s = '3.14'
print(float(s))
print(int(float(s)))
Expected Output
3.14
3

Python Program to Get the Last Element of the List

Index -1.

Source Code
print([1,2,3][-1])
Expected Output
3

Python Program to Randomly Select an Element From the List

Uses random.choice.

Source Code
import random
random.seed(0)
print(random.choice([10,20,30]))
Expected Output
20

Python Program to Get the Class Name of an Instance

Uses __class__.__name__.

Source Code
class A: pass
print(A().__class__.__name__)
Expected Output
A

Python Program to Reverse a Number

Reverses digits.

Source Code
n = 1234
print(int(str(n)[::-1]))
Expected Output
4321

Python Program to Compute all the Permutation of the String

Uses itertools.permutations.

Source Code
import itertools
s = 'abc'
perms = [''.join(p) for p in itertools.permutations(s)]
print(perms)
Expected Output
['abc', 'acb', 'bac', 'bca', 'cab', 'cba']

Python Program to Create a Countdown Timer

Simple countdown.

Source Code
for i in range(3,0,-1):
    print(i)
Expected Output
3
2
1

Python Program to Convert Bytes to a String

Decodes bytes.

Source Code
print(b'hello'.decode('utf-8'))
Expected Output
hello

Python Program to Find the Square Root

Computes square root using math module.

Source Code
import math
print(math.sqrt(16))
Expected Output
4.0

Python Core Concepts & Decision Breakdown

CategoryCore ConceptsPrimary Use CaseOfficial Docs
Primitives & Basicsint, float, str, boolBasic arithmetic, logic checks, string formattingBuilt-in Types
Data Structureslist, tuple, dict, setCollections, lookup maps, data filteringData Structures
Control Flowif/else, for, while, try/exceptIteration, conditional execution, error handlingControl Flow
OOP & Modulardef, class, lambda, importObject orientation, modularization, reusabilityClasses & OOP

Keep Practicing

Use the online Python compiler to run examples and test variations. Reinforce learning by building small scripts for each topic.

Frequently Asked Questions

Python is a high-level, interpreted programming language known for readable syntax. Practicing with runnable examples accelerates learning by reinforcing concepts through immediate feedback.

You can run all examples instantly using our integrated Online Python Compiler directly in your web browser without downloading any software.

Yes. The programs cover foundational topics including arithmetic, strings, lists, dictionaries, recursion, algorithms, and file operations commonly tested in coding interviews.

Yes. All snippets use standard Python 3 syntax and libraries, ensuring cross-platform compatibility across Windows, macOS, Linux, and web-based environments.

Learn Python by Practicing Examples

Hands-on practice is the fastest way to understand Python. Each example focuses on a single concept—from variables, strings, lists, and dictionaries to loops, functions, classes, exceptions, and file I/O. Modify examples, add new functions, and see how clean design leads to readable, maintainable code.

Use our tools to deepen learning: the Python Compiler to run snippets, the Python Official Docs for language standards, and the Python Tutorial for structured lessons.

Beginner-Friendly

Start with variables, operators, and control flow. Build confidence with small, readable programs.

Practical Patterns

Practice lists, dicts, comprehensions, functions, classes, exceptions, and file handling.

Grow Skills

Explore generators and decorators to write expressive, reusable code.