Python Programs
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.
- Add two numbers
- Maximum of two numbers
- Factorial of a number
- Find simple interest
- Find compound interest
- Check Armstrong Number
- Find area of a circle
- Print all Prime numbers in an Interval
- Check whether a number is Prime or not
- N-th Fibonacci number
- Check if a given number is Fibonacci number?
- Nth multiple of a number in Fibonacci Series
- Print ASCII Value of a character
- Sum of squares of first n natural numbers
- Cube sum of first n natural numbers

Array 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.
- Find sum of array
- Find largest element in an array
- Program for array rotation
- Reversal algorithm for array rotation
- Split the array and add the first part to the end
- Find reminder of array multiplication divided by n
- Check if given array is Monotonic
List Programs
Explore the below section and try out all the important Python List programming examples.
- Interchange first and last elements in a list
- Swap two elements in a list
- Ways to find length of list
- Ways to check if element exists in list
- Different ways to clear a list
- Reversing a List
- Find sum of elements in list
- Multiply all numbers in the list
- Find smallest number in a list
- Find largest number in a list
- Find second largest number in a list
- Find N largest elements from a list
- Even numbers in a list
- Odd numbers in a List
- Print all even numbers in a range
- Print all odd numbers in a range
- Print positive numbers in a list
- Print negative numbers in a list
- Print all positive numbers in a range
- Print all negative numbers in a range
- Remove multiple elements from a list
- Remove empty List from List
- Cloning or Copying a list
- Count occurrences of an element in a list
- Remove empty tuples from a list
- Print duplicates from a list of integers
- Find Cumulative sum of a list
- Sum of number digits in List
- Break a list into chunks of size N
- Sort the values of first list using second list
- More >>
Matrix Programs
Get a detailed list of Python Matrix examples and boost your understanding of matrix concepts in Python.
- Add two Matrices
- Multiply two matrices
- Matrix Product
- Adding and Subtracting Matrices
- Transpose a matrix in Single line
- Matrix creation of n*n
- Get Kth Column of Matrix
- 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.
- Check if a string is palindrome or not
- Check whether the string is Symmetrical or Palindrome
- Reverse words in a given String
- Ways to remove i’th character from string
- Check if a Substring is Present in a Given String
- Words Frequency in String Shorthands
- Convert Snake case to Pascal case
- Find length of a string (4 ways)
- Print even length words in a string
- Accept the strings which contains all vowels
- Count the Number of matching characters in a pair of string
- Remove all duplicates from a given string
- Least Frequent Character in String
- Maximum frequency character in String
- Check if a string contains any special character
- Generating random strings until a given string is generated
- Find words which are greater than given length k
- Removing i-th character from a string
- Split and join a string
- Check if a given string is binary string or not
- Find uncommon words from two Strings
- Replace duplicate Occurrence in String
- Replace multiple words with K
- Permutation of a given string using inbuilt function
- Check for URL in a String
- Execute a String of Code
- String slicing to rotate a string
- String slicing to check if a string can become empty by recursive deletion
- Counter| Find all duplicate characters in string
- Replace all occurrences of a substring in a string
- More >>
Dictionary Programs
In this section, you will find out all the important practice sets or examples related to the Python Dictionary concept.
- Extract Unique values dictionary values
- Find the sum of all items in a dictionary
- Ways to remove a key from dictionary
- Ways to sort list of dictionaries by values Using itemgetter
- Ways to sort list of dictionaries by values Using lambda function
- Merging two Dictionaries
- Convert key-values list to flat dictionary
- Insertion at the beginning in OrderedDict
- Check order of character in string using OrderedDict( )
- Dictionary and counter to find winner of election
- Append Dictionary Keys and Values ( In order ) in dictionary
- Sort Python Dictionaries by Key or Value
- Sort Dictionary key and values List
- Handling missing keys in Python dictionaries
- Dictionary with keys having multiple inputs
- Print anagrams together using List and Dictionary
- K’th Non-repeating Character using List Comprehension and OrderedDict
- Check if binary representations of two numbers are anagram
- Counter to find the size of largest subset of anagram words
- Remove all duplicates words from a given sentence
- Dictionary to find mirror characters in a string
- Counting the frequencies in a list using dictionary
- Convert a list of Tuples into Dictionary
- Counter and dictionary intersection example (Make a string using deletion and rearrangement)
- Dictionary, set and counter to check if frequencies can become same
- Scraping And Finding Ordered Words In A Dictionary
- Possible Words using given characters
- Keys associated with Values in Dictionary
More >>
Tuple Programs
Explore the wide range of Tuple programs here in this section of Python programming examples.
- Find the size of a Tuple
- Maximum and Minimum K elements in Tuple
- Create a list of tuples from given list having number and its cube in each tuple
- Adding Tuple to List and vice – versa
- Closest Pair to Kth index element in Tuple
- Join Tuples if similar initial element
- Extract digits from Tuple list
- All pair combinations of 2 tuples
- Remove Tuples of Length K
- Sort a list of tuples by second Item
- Order Tuples using external List
- Flatten tuple of List to tuple
- 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.
- Binary Search (Recursive and Iterative)
- Linear Search
- Insertion Sort
- Recursive Insertion Sort
- QuickSort
- Iterative Quick Sort
- Selection Sort
- Bubble Sort
- Merge Sort
- Iterative Merge Sort
- Heap Sort
- Counting Sort
- ShellSort
- Topological Sorting
- Radix Sort
- Binary Insertion Sort
- Bitonic Sort
- Comb Sort
- Pigeonhole Sort
- Cocktail Sort
- Gnome Sort
- Odd-Even Sort / Brick Sort
- BogoSort or Permutation Sort
- Cycle Sort
- Stooge Sort
Pattern Printing Programs
Get a complete list of Python pattern printing examples in the below section.
- Print the pattern ‘G’
- Print an Inverted Star Pattern
- Print double sided stair-case pattern
- Print with your own font
Date-Time Programs
In this section, we have mentioned all important Python program examples that are related to the Python Date-Time concept.
- Get Current Time
- Get Current Date and Time
- Find yesterday’s, today’s and tomorrow’s date
- Convert time from 12 hour to 24 hour format
- Find difference between current time and given time
- Create a Lap Timer
- Convert date string to timestamp
- Convert timestamp string to datetime object?
- Find number of times every day occurs in a Year
Python Regex Programs
To boost Python Regex concept get a list of Python Regex programming examples below.
- Check if String Contain Only Defined Characters using Regex
- Count Uppercase, Lowercase, special character and numeric values using Regex
- Find the most occurring number in a string using Regex
- Regex to extract maximum numeric value from a string
- Program to put spaces between words starting with capital letters using Regex
- Check whether a string starts and ends with the same character or not
- Regex to find sequences of one upper case letter followed by lower case letters
- Remove duplicate words from Sentence
- Remove all characters except letters and numbers
- Accept string ending with alphanumeric character
- Accept string starting with vowel
- Check if a string starts with a substring using regex
- Check if an URL is valid or not using Regular Expression
- Parsing and Processing URL – Regex
- Validate an IP address using ReGex
- Check if email address valid or not
- Find files having a particular extension using RegEx
- Extract IP address from file
- Check the validity of a Password
- Categorize Password as Strong or Weak using Regex
Python 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.
- Read file word by word
- Read character by character from a file
- Get number of characters, words, spaces and lines in a file
- Count the Number of occurrences of a key-value pair in a text file
- Finding ‘n’ Character Words in a Text File
- Obtain the line number in which given word is present
- Count number of lines in a text file
- Remove lines starting with any prefix
- Eliminate repeated lines from a file
- Read List of Dictionaries from File
- Append content of one text file to another
- Copy odd lines of one file to other
- Merge two files into a third file
- Reverse a single line of a text file
- Reverse the content of a file and store it in another file
- Reverse the Content of a File using Stack
More Popular Python Programs
Find a more important or popular list of Python programming examples below and upscale your Python programming skills.
- Reverse a linked list
- Find largest prime factor of a number
- Efficient program to print all prime factors of a given number
- Product of unique prime factors of a number
- Find sum of odd factors of a number
- Program for Coin Change
- Program for Tower of Hanoi
- Sieve of Eratosthenes
- Check if binary representation is palindrome
- Basic Euclidean algorithms
- Extended Euclidean algorithms
- Maximum height when coins are arranged in a triangle
- Find minimum sum of factors of number
- Difference between sums of odd and even digits
- Print Matrix in Z form
- Smallest K digit number divisible by X
- Print Number series without using any loop
- Number of stopping station problem
- Check if a triangle of positive area is possible with the given angles
- Find the most occurring character and its count
- Find sum of even factors of a number
- Check if all digits of a number divide it
- Check whether a number has consecutive 0’s in the given base or not
- Number of solutions to Modular Equations
- Legendre’s Conjecture
Python Programs - FAQs
What are programs in Python?
Python programs are sets of instructions written in the Python programming language. These instructions, or code, are executed by the Python interpreter to perform specific tasks, ranging from simple functions like adding numbers to complex operations like web development or data analysis. A Python program typically includes elements like variables, functions, and control structures that work together to manipulate data and produce desired outcomes.
What are some common codes in Python?
Common codes in Python include solutions for tasks such as:
- String manipulation (e.g., reversing strings)
- Mathematical problems (e.g., factorial, Fibonacci)
- Data structure operations (e.g., lists, sets, dictionaries)
- File handling (e.g., reading and writing files) These codes are widely used and often serve as building blocks for larger programs.
How to write Python programs?
To write Python programs, follow these steps:
1. Define the Problem: Understand and outline what you want your program to achieve.
2. Set Up Environment: Install Python and set up a code editor or IDE to write your code.
3. Write Code: Start by importing necessary libraries, if needed. Use variables, functions, and control structures to build your program.
4. Test and Debug: Run your program to see if it works as expected. Fix any issues by debugging your code.
5. Refine: Optimize and refactor your code for better efficiency and readability.
6. Document: Add comments and documentation to explain what your code does.
By practicing these steps, you can progressively handle more complex projects and enhance your programming skills.
What does programming Python code involve?
Programming Python code involves writing scripts or applications using the Python language. Python’s simple syntax makes it ideal for beginners, and its vast ecosystem supports complex tasks such as data analysis, machine learning, web development, and automation. Examples of Python code cover a range of topics like algorithms, file handling, and web scraping.
What are Python 3 programs?
Python 3 programs refer to scripts and applications written specifically for Python version 3, the latest major release of Python. Python 3 introduced several new features and syntax changes, making it more efficient and modern compared to Python 2. Most new programming examples, including those found online, follow Python 3 standards.
What is a Py program?
A Py program is a general term used to refer to any program or script written in the Python language. "Py" is a shorthand commonly used to reference Python, and you may see it in file names (e.g.,
.py
extension), packages, and documentation. A Py program can range from a simple "Hello World" script to complex machine learning applications.