Python Programs

Last Updated : 17 Aug, 2026

Practice with Python program examples is always a good choice to scale up your logical understanding and programming skills and this article will provide you with the best sets of Python code examples.

The below Python section contains a wide collection of Python programming examples. These Python code examples cover a wide range of basic concepts in the Python language, including List, Strings, Dictionary, Tuple, sets and many more. Each program example contains multiple approaches to solve the problem.

Basic Python Programs

In this section, you will find all the basic Python programming examples. So, explore the section and complete the basic stage of Python programming.

  1. Add two numbers
  2. Maximum of two numbers
  3. Factorial of a number
  4. Find simple interest
  5. Find compound interest
  6. Check Armstrong Number
  7. Find area of a circle
  8. Check whether a number is Prime or not
  9. N-th Fibonacci number
  10. Nth multiple of a number in Fibonacci Series
  11. Print ASCII Value of a character
  12. Cube sum of first n natural numbers

Array / List Programs

To scale up Array logic, try out the below-listed Python array programming examples. Here, you will find all the important Python programming examples that are related to the Python array concept.

  1. Largest element in an array
  2. Array rotation
  3. Reversal algorithm for array rotation
  4. Split and Rotate an Array
  5. Find Remainder of Array Product
  6. Check if given array is Monotonic
  7. Interchange first and last elements in a list
  8. Swap two elements in a list
  9. Find Length of a List
  10. Ways to check if element exists in list
  11. Clear a List
  12. Reversing a List
  13. Find sum of elements in list
  14. Multiply all numbers in the list
  15. Find smallest number in a list
  16. Find second largest number in a list
  17. Find N largest elements in a list
  18. Print all even numbers in a range
  19. Print all odd numbers in a range
  20. Print positive numbers in a list
  21. Print negative numbers in a list
  22. Print all positive numbers in a range
  23. Print all negative numbers in a range
  24. Remove multiple elements from a list
  25. Remove empty List from List
  26. Cloning or Copying a list
  27. Count occurrences of an element in a list
  28. Remove empty tuples from a list
  29. Print duplicates from a list of integers
  30. Find Cumulative sum of a list
  31. Sum of number digits in List
  32. Break a list into chunks of size N
  33. Sort the values of first list using second list

Matrix Programs

Get a detailed list of Python Matrix examples and boost your understanding of matrix concepts in Python.

  1. Add two Matrices
  2. Multiply two matrices
  3. Matrix Product
  4. Adding and Subtracting Matrices
  5. Matrix creation of n*n
  6. Get Kth Column of Matrix
  7. Vertical Concatenation in Matrix

String Programs

If you are looking for Python programming examples that are based on the Python string concept, then scroll down to the below section and practice a wide range of Python string program examples.

  1. Check if a string is palindrome or not
  2. Reverse words in a given String
  3. Ways to remove i’th character from string
  4. Check if a Substring is Present in a Given String
  5. Find Word Frequency in a String
  6. Convert Snake case to Pascal case
  7. Find length of a string (4 ways)
  8. Print even length words in a string
  9. Check if a String Contains All Vowels
  10. Count Matching Characters in Two Strings
  11. Remove all duplicates from a given string
  12. Least Frequent Character in String
  13. Maximum frequency character in String
  14. Split and join a string
  15. Check if a given string is binary string or not
  16. Find uncommon words from two Strings
  17. Replace duplicate Occurrence in String
  18. Replace multiple words with K
  19. Check for URL in a String
  20. Execute a String of Code
  21. String slicing to rotate a string
  22. Check if a String Can Become Empty by Recursive Deletion
  23. Counter| Find all duplicate characters in string
  24. Replace all occurrences of a substring in a string

Dictionary Programs

In this section, you will find out all the important practice sets or examples related to the Python Dictionary concept.

  1. Extract Unique values dictionary values
  2. Find the sum of all items in a dictionary
  3. Ways to remove a key from dictionary
  4. Sort List of Dictionaries by Value Using itemgetter
  5. Sort List of Dictionaries by Value Using Lambda
  6. Merging two Dictionaries
  7. Convert key-values list to flat dictionary
  8. Insertion at the beginning in OrderedDict
  9. Check order of character in string using OrderedDict( )
  10. Append Dictionary Keys and Values in Order
  11. Sort Python Dictionaries by Key or Value
  12. Handling missing keys in Python dictionaries
  13. Dictionary with keys having multiple inputs
  14. Print anagrams together using List and Dictionary
  15. K-th Non-Repeating Character Using OrderedDict
  16. Check if binary representations of two numbers are anagram
  17. Counter to find the size of largest subset of anagram words
  18. Remove all duplicates words from a given sentence
  19. Dictionary to find mirror characters in a string
  20. Counting the frequencies in a list using dictionary
  21. Convert a list of Tuples into Dictionary
  22. Find Ordered Words in a Dictionary
  23. Possible Words using given characters
  24. Keys associated with Values in Dictionary

Tuple Programs

Explore the wide range of Tuple programs here in this section of Python programming examples.

  1. Find the size of a Tuple
  2. Maximum and Minimum K elements in Tuple
  3. Create Tuples of Numbers and Their Cubes
  4. Adding Tuple to List and vice – versa
  5. Closest Pair to Kth index element in Tuple
  6. Join Tuples if similar initial element
  7. Extract digits from Tuple list
  8. All pair combinations of 2 tuples
  9. Remove Tuples of Length K
  10. Sort a list of tuples by second Item
  11. Order Tuples using external List
  12. Flatten tuple of List to tuple
  13. Convert Nested Tuple to Custom Key Dictionary

Searching and Sorting Programs

In this section, on searching and sorting examples, we have mentioned all the important example sets of Python searching and sorting to boost your Python programming concept.

  1. Binary Search (Recursive and Iterative)
  2. Linear Search
  3. Insertion Sort
  4. Recursive Insertion Sort
  5. QuickSort
  6. Iterative Quick Sort
  7. Selection Sort
  8. Bubble Sort
  9. Merge Sort
  10. Iterative Merge Sort
  11. Heap Sort
  12. Counting Sort
  13. ShellSort
  14. Topological Sorting
  15. Radix Sort
  16. Binary Insertion Sort
  17. Bitonic Sort
  18. Comb Sort
  19. Pigeonhole Sort
  20. Cocktail Sort
  21. Gnome Sort
  22. Odd-Even Sort / Brick Sort
  23. BogoSort or Permutation Sort
  24. Cycle Sort
  25. Stooge Sort

Pattern Printing Programs

Get a complete list of Python pattern printing examples in the below section.

  1. Print an Inverted Star Pattern
  2. Print Double-Sided Staircase Pattern

Date-Time Programs

In this section, we have mentioned all important Python program examples that are related to the Python Date-Time concept.

  1. Get Current Date and Time
  2. Find yesterday’s, today’s and tomorrow’s date
  3. Convert time from 12 hour to 24 hour format
  4. Find difference between current time and given time
  5. Create a Lap Timer
  6. Convert date string to timestamp
  7. Convert timestamp string to datetime object

Python Regex Programs

To boost Python Regex concept get a list of Python Regex programming examples below.

  1. Check if String Contain Only Defined Characters
  2. Count Character Types
  3. Find the most occurring number in a string
  4. Extract maximum numeric value from a string
  5. Add Spaces Before Capital Letters
  6. Check whether a string starts and ends with the same character or not
  7. Find Uppercase-Lowercase Sequences
  8. Remove duplicate words from Sentence
  9. Remove all characters except letters and numbers
  10. Accept string ending with alphanumeric character
  11. Accept string starting with vowel
  12. Check if a string starts with a substring
  13. Check if an URL is valid or not
  14. Parsing and Processing URL
  15. Validate an IP address
  16. Check if email address valid or not
  17. Find files having a particular extension
  18. Extract IP address from file
  19. Check the validity of a Password
  20. Categorize Password as Strong or Weak

File Handling Programs

If you want to scale up your Python file handling concept, explore the below section and find out all the real-life Python programming examples on Python file handling.

  1. Read file word by word
  2. Read character by character from a file
  3. Count Characters, Words, Spaces and Lines in a File
  4. Count the Number of occurrences of a key-value pair in a text file
  5. Finding ‘n’ Character Words in a Text File
  6. Find Line Number of a Word in a File
  7. Count number of lines in a text file
  8. Remove lines starting with any prefix
  9. Eliminate repeated lines from a file
  10. Read List of Dictionaries from File
  11. Append content of one text file to another
  12. Copy odd lines of one file to other
  13. Merge two files into a third file
  14. Reverse a single line of a text file
  15. Reverse the content of a file and store it in another file
  16. Reverse the Content of a File using Stack

Find a more important or popular list of Python programming examples below and upscale your Python programming skills.

  1. Reverse a linked list
  2. Find largest prime factor of a number
  3. Efficient program to print all prime factors of a given number
  4. Product of unique prime factors of a number
  5. Find sum of odd factors of a number
  6. Print all Prime numbers in an Interval
  7. Program for Coin Change
  8. Program for Tower of Hanoi
  9. Sieve of Eratosthenes
  10. Check if binary representation is palindrome
  11. Basic Euclidean algorithms
  12. Extended Euclidean algorithms
  13. Find Maximum Height of a Coin Triangle
  14. Find minimum sum of factors of number
  15. Difference between sums of odd and even digits
  16. Print Matrix in Z form
  17. Smallest K digit number divisible by X
  18. Print Number series without using any loop
  19. Number of stopping station problem
  20. Check if a Triangle Is Possible from Given Angles
  21. Find the most occurring character and its count
  22. Find sum of even factors of a number
  23. Check if all digits of a number divide it
  24. Check whether a number has consecutive 0’s in the given base or not
  25. Number of solutions to Modular Equations
  26. Legendre’s Conjecture

For more Practice problems and Programs refer to Python Exercise with Practice Questions and Solutions

Comment