Python Programs
发布时间:2026-09-07 | 浏览:2
Python Tutorial
Interview Questions
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
Check whether a number is Prime or not
N-th Fibonacci number
Nth multiple of a number in Fibonacci Series
Print ASCII Value of a character
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.
Largest element in an array
Reversal algorithm for array rotation
Split and Rotate an Array
Find Remainder of Array Product
Check if given array is Monotonic
Interchange first and last elements in a list
Swap two elements in a list
Find Length of a List
Ways to check if element exists in list
Reversing a List
Find sum of elements in list
Multiply all numbers in the list
Find smallest number in a list
Find second largest number in a list
Find N largest elements 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
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
Adding and Subtracting Matrices
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
Reverse words in a given String
Ways to remove i’th character from string
Check if a Substring is Present in a Given String
Find Word Frequency in a String
Convert Snake case to Pascal case
Find length of a string (4 ways)
Print even length words in a string
Check if a String Contains All Vowels
Count Matching Characters in Two Strings
Remove all duplicates from a given string
Least Frequent Character in String
Maximum frequency character in 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
Check for URL in a String
Execute a String of Code
String slicing to rotate a string
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
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
Sort List of Dictionaries by Value Using itemgetter
Sort List of Dictionaries by Value Using Lambda
Merging two Dictionaries
Convert key-values list to flat dictionary
Insertion at the beginning in OrderedDict
Check order of character in string using OrderedDict( )
Append Dictionary Keys and Values in Order
Sort Python Dictionaries by Key or Value
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 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
Find Ordered Words in a Dictionary
Possible Words using given characters
Keys associated with Values in Dictionary
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 Tuples of Numbers and Their Cubes
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)
Recursive Insertion Sort
Iterative Quick Sort
Iterative Merge Sort
Topological Sorting
Binary Insertion Sort
Pigeonhole Sort
Odd-Even Sort / Brick Sort
BogoSort or Permutation Sort
Pattern Printing Programs
Get a complete list of Python pattern printing examples in the below section.
Print an Inverted Star Pattern
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.
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
Python Regex Programs
To boost Python Regex concept get a list of Python Regex programming examples below.
Check if String Contain Only Defined Characters
Count Character Types
Find the most occurring number in a string
Extract maximum numeric value from a string
Add Spaces Before Capital Letters
Check whether a string starts and ends with the same character or not
Find Uppercase-Lowercase Sequences
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
Check if an URL is valid or not
Parsing and Processing URL
Validate an IP address
Check if email address valid or not
Find files having a particular extension
Extract IP address from file
Check the validity of a Password
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.
Read file word by word
Read character by character from a file
Count 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
Find Line Number of a Word in a File
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
Print all Prime numbers in an Interval
Program for Coin Change
Program for Tower of Hanoi
Sieve of Eratosthenes
Check if binary representation is palindrome
Basic Euclidean algorithms
Extended Euclidean algorithms
Find Maximum Height of a Coin 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 Is Possible from 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
For more Practice problems and Programs refer to Python Exercise with Practice Questions and Solutions
Introduction 1 min read
Input & Output 2 min read
Variables 4 min read
Operators 4 min read
Keywords 2 min read
Data Types 4 min read
Conditional Statements 3 min read
Loops 3 min read
Functions 4 min read
String 4 min read
List 3 min read
Tuples 3 min read
Dictionary 3 min read
Arrays 5 min read
OOP Concepts 3 min read
Exception Handling 5 min read
File Handling 4 min read
Python Database 4 min read
MongoDB 3 min read
MySQL 7 min read
Packages 4 min read
Modules 3 min read
DSA Libraries 5 min read
Python GUI 2 min read
Numpy 3 min read
Pandas 4 min read
Matplotlib 3 min read
Seaborn 3 min read
StatsModel 2 min read
Model Building 6 min read
TensorFlow 2 min read
PyTorch 5 min read
Flask 3 min read
Django 5 min read
Django ORM 4 min read
Jinja2 Templating 5 min read
Django Templates 5 min read
REST API 3 min read
Build API with DRF 4 min read
Quiz 1 min read
Practice Problems 2 min read
Interview Q & A 15+ min read
Placement 360 Course 2 min read
Data Science 360 Course 2 min read
AI Engg Course 2 min read