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.
Quick Start & How to Use
- Select a Python example topic from the sidebar menu (or mobile dropdown).
- Examine the structured source code and corresponding expected output.
- Copy code directly or test it in our Online Python Compiler.
- 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 Merge Mails
Simple mail merge.
names = ['Ann','Bob']
template = 'Hello {name}, welcome.'
msgs = [template.format(name=n) for n in names]
print('\n'.join(msgs))Hello Ann, welcome. Hello Bob, welcome.
Python Program to Shuffle Deck of Cards
Shuffles deck deterministically.
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])
['7C', '5H', 'QD', '2S', '3D']
Python Program to Display Calendar
Shows month calendar.
import calendar print(calendar.month(2025, 1))
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 31Python Program to Find the Size (Resolution) of an Image
Uses Pillow for image size.
from PIL import Image
img = Image.new('RGB', (640, 480))
print(img.size)(640, 480)
Python Program to Merge Two Dictionaries
Merges using unpack.
a = {'x':1}
b = {'y':2}
c = {**a, **b}
print(c){'x': 1, 'y': 2}Python Program to Access Index of a List Using for Loop
Uses enumerate.
lst = ['a','b','c']
for i, v in enumerate(lst):
print(i, v)0 a 1 b 2 c
Python Program to Split a List Into Evenly Sized Chunks
Chunking utility.
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))[[1, 2], [3, 4], [5]]
Python Program to Parse a String to a Float or Int
Converts string.
s = '3.14' print(float(s)) print(int(float(s)))
3.14 3
Python Program to Get the Last Element of the List
Index -1.
print([1,2,3][-1])
3
Python Program to Randomly Select an Element From the List
Uses random.choice.
import random random.seed(0) print(random.choice([10,20,30]))
20
Python Program to Get the Class Name of an Instance
Uses __class__.__name__.
class A: pass print(A().__class__.__name__)
A
Python Program to Reverse a Number
Reverses digits.
n = 1234 print(int(str(n)[::-1]))
4321
Python Program to Check If Two Strings are Anagram
Compares sorted letters.
def anagram(a,b):
return sorted(a.replace(' ','').lower()) == sorted(b.replace(' ','').lower())
print(anagram('listen','silent'))True
Python Program to Compute all the Permutation of the String
Uses itertools.permutations.
import itertools s = 'abc' perms = [''.join(p) for p in itertools.permutations(s)] print(perms)
['abc', 'acb', 'bac', 'bca', 'cab', 'cba']
Python Program to Create a Countdown Timer
Simple countdown.
for i in range(3,0,-1):
print(i)3 2 1
Python Program to Convert Bytes to a String
Decodes bytes.
print(b'hello'.decode('utf-8'))hello
Python Program to Find the Square Root
Computes square root using math module.
import math print(math.sqrt(16))
4.0
Python Core Concepts & Decision Breakdown
| Category | Core Concepts | Primary Use Case | Official Docs |
|---|---|---|---|
| Primitives & Basics | int, float, str, bool | Basic arithmetic, logic checks, string formatting | Built-in Types |
| Data Structures | list, tuple, dict, set | Collections, lookup maps, data filtering | Data Structures |
| Control Flow | if/else, for, while, try/except | Iteration, conditional execution, error handling | Control Flow |
| OOP & Modular | def, class, lambda, import | Object orientation, modularization, reusability | Classes & 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
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.