Python is an interpreted, object-oriented, and high-level programming language with dynamic semantics. Python is an easy-to-use, beginner-friendly programming language primarily used for web development, application and game development, AI, ML, automation, Software development, GUI development, etc. This section contains a wide range of Python programming examples from basic programs to complex and advanced Python programs.

These examples range from simple Python programs to Mathematical functions, lists, strings, sets, Python dictionaries, tuples, recursions, file handling, classes and objects, linked list, stacks, queues, searching and sorting, trees, heap, graphs, games, greedy algorithms, and dynamic programming. Every example program includes the problem description, problem solution, source code, program explanation, and run-time test cases. All Python examples have been compiled and tested on Windows and Linux systems.

**Here is the listing of Python Topics:**

- Simple Python Programs
- Python Programs on Numbers
- Factorial & Fibonacci Programs in Python
- Conversion Programs in Python
- Pattern Programs in Python
- Python Programs on Math Functions
- Python Programs on Progression Series
- Python Programs on GCD and LCM
- Python Programs on Strings
- Python Programs on Dictionary
- Python Programs on Tuples
- Python Programs on Classes & Objects
- Python Programs on File Handling
- Python Programs on List

- Python Programs on Linked List
- Python Programs on Singly Linked List
- Python Programs on Doubly Linked List
- Python Programs on Stack
- Python Programs on Queue
- Python Programs on Tree
- Python Programs on Heap
- Python Programs on Graph
- Python Programs on Searching
- Python Programs on Sorting
- Python Programs on Gaming
- Python Greedy Algorithms
- Python Programs on Dynamic Programming

## Simple Python Programs

- Python Program to Check Whether a Given Number is Even or Odd using Recursion
- Python Program to Check Whether a Number is Positive or Negative
- Python Program to Print All Odd Numbers in a Range
- Python Program to Check if a Number is a Palindrome
- Python Program to Reverse a Number
- Python Program to Print All Integers that Aren’t Divisible by Either 2 or 3
- Python Program to Find Numbers which are Divisible by 7 and Multiple of 5 in a Given Range
- Python Program to Print All Numbers in a Range Divisible by a Given Number
- Python Program to Find Sum of Digits of a Number
- Python Program to Find Sum of Digit of a Number using Recursion
- Python Program to Find Sum of Digit of a Number Without Recursion
- Python Program to Count the Number of Digits in a Number
- Python Program to Find All the Divisors of an Integer
- Python Program to Find the Smallest Divisor of an Integer
- Python Program to Print Binary Equivalent of an Integer using Recursion
- Python Program to Print Binary Equivalent of a Number without Using Recursion
- Python Program to Print Table of a Given Number
- Python Program to Calculate Grade of a Student
- Python Program to Check if a Date is Valid and Print the Incremented Date if it is
- Python Program to Check Whether a given Year is a Leap Year
- Python Program to Convert Centimeters to Feet and Inches
- Python Program to Read a Number n and Compute n+nn+nnn

## Python Programs on Numbers

- Python Program to Find Prime Numbers in a Given Range
- Python Program to Check Prime Number
- Python Program to Check whether a Number is Prime or Not using Recursion
- Python Program to Check Whether a Given Number is Perfect Number
- Python Program to Check Armstrong Number
- Python Program to Find Sum of First N Natural Numbers
- Python Program to Check if a Number is a Strong Number
- Python Program to Print Numbers in a Range Without using Loops
- Python Program to Print the Natural Numbers Summation Pattern
- Python Program to Find the Prime Factors of a Number
- Python Program to Check If Two Numbers are Amicable Numbers or Not
- Python Program to Find Whether a Number is a Power of Two
- Python Program to Calculate the Power using Recursion
- Python Program to Find Product of Two Numbers using Recursion
- Python Program to Find All Perfect Squares in the Given Range
- Python Program to Print All Possible Combinations of Three Digits

## Fibonacci Programs in Python

- Python Program to Find Fibonacci Numbers using Recursion
- Python Program to Find the Fibonacci Series Without using Recursion
- Python Program to Find the Factorial of a Number using Recursion
- Python Program to Find the Factorial of a Number Without Recursion

## Conversion Programs in Python

- Python Program to Convert Binary to Gray Code
- Python Program to Generate Gray Codes using Recursion
- Python Program to Convert Gray to Binary Code
- Python Program to Convert Celsius to Fahrenheit

## Pattern Programs in Python

## Python Programs on Math Functions

- Python Program to Find the Roots of a Quadratic Equation
- Python Program to Find the Area of a Triangle
- Python Program to Find Simple Interest
- Python Program to Find Quotient and Remainder of Two Numbers
- Python Program to Find All Pythagorean Triplets in the Range
- Python Program to Compute a Polynomial Equation
- Python Program to Swap Two Numbers without using Third Variable
- Python Program to Count Set Bits in an Integer
- Python Program to Clear the Rightmost Set Bit of a Number
- Python Program to Test Collatz Conjecture for a Given Number
- Python Program to Find the Gravitational Force between Two Objects
- Python Program to Form an Integer that has Number of Digits at 10’s Place & LSD at 1’s Place
- Python Program to Print an Identity Matrix

## Python Programs on Progression Series

- Python Program to Find Sum of Series 1 + 1/2 + 1/3 + 1/4 + ……. + 1/N
- Python Program to Find the Sum of the Series 1/1!+1/2!+1/3!+…1/N!
- Python Program to Find the Sum of the Series: 1 + x^2/2 + x^3/3 + … x^n/n
- Python Program to Read a Number n and Print the Series “1+2+…..+n= “
- Python Program to Find the Sum of Sine Series
- Python Program to Find the Sum of Cosine Series

## Python Programs on GCD and LCM

- Python Program to Find the LCM of Two Numbers
- Python Program to Find the GCD of Two Numbers
- Python Program to Find the GCD of Two Numbers using Recursion
- Python Program to Find the LCM of Two Numbers using Recursion

## Python Programs on Strings

- Python Program to Check if a String is a Pangram or Not
- Python Program to Remove Odd Indexed Characters in a string
- Python Program to Remove the nth Index Character from a Non-Empty String
- Python Program to Replace All Occurrences of ‘a’ with $ in a String
- Python Program to Replace Every Blank Space with Hyphen in a String
- Python Program to Reverse a String using Recursion
- Python Program to Reverse a String Without using Recursion
- Python Program to Determine How Many Times a Given Letter Occurs in a String Recursively
- Python Program to Find the Length of a String without Library Function
- Python Program to Count the Number of Words and Characters in a String
- Python Program to Count Number of Lowercase Characters in a String
- Python Program to Count the Number of Vowels in a String
- Python Program to Count Number of Uppercase and Lowercase Letters in a String
- Python Program to Count the Number of Digits and Letters in a String
- Python Program to Print All Permutations of a String in Lexicographic Order using Recursion
- Python Program to Print All Permutations of a String in Lexicographic Order without Recursion
- Python Program to Check if the Substring is Present in the Given String
- Python Program to Find Common Characters in Two Strings
- Python Program to Print All Letters Present in Both Strings
- Python Program that Displays which Letters are in First String but not in Second
- Python Program that Displays Letters that are not Common in Two Strings
- Python Program to Create a New String Made up of First and Last 2 Characters
- Python Program to Find the Larger String without using Built-in Functions
- Python Program to Swap the First and the Last Character of a String
- Python Program to Sort Hyphen Separated Sequence of Words in Alphabetical Order
- Python Program to Count the Occurrences of Each Word in a String
- Python Program to Count Number of Vowels in a String using Sets
- Python Program to Check if a Given String is Palindrome
- Python Program to Check whether two Strings are Anagrams
- Python Program to Check whether a String is Palindrome or not using Recursion
- Python Program to Find All Odd Palindrome Numbers in a Range without using Recursion

## Python Programs on Dictionary

- Python Program to Create Dictionary from an Object
- Python Program to Check if a Key Exists in a Dictionary or Not
- Python Program to Add a Key-Value Pair to the Dictionary
- Python Program to Find the Sum of All the Items in a Dictionary
- Python Program to Multiply All the Items in a Dictionary
- Python Program to Remove a Key from a Dictionary
- Python Program to Concatenate Two Dictionaries
- Python Program to Map Two Lists into a Dictionary
- Python Program to Create a Dictionary with Key as First Character and Value as Words Starting with that Character
- Python Program to Create Dictionary that Contains Number
- Python Program to Count the Frequency of Each Word in a String using Dictionary

## Python Programs on Tuples

- Python Program to Create a List of Tuples with the First Element as the Number and Second Element as the Square of the Number
- Python Program to Remove All Tuples in a List Outside the Given Range
- Python Program to Sort a List of Tuples in Increasing Order by the Last Element in Each Tuple

## Python Programs on Classes & Objects

- Python Program to Create a Class which Performs Basic Calculator Operations
- Python Program to Append, Delete and Display Elements of a List using Classes
- Python Program to Find the Area of a Rectangle using Classes
- Python Program to Find the Area and Perimeter of the Circle using Class
- Python Program to Create a Class in which One Method Accepts a String from the User and Another Prints it
- Python Program to Create a Class and Get All Possible Distinct Subsets from a Set

## Python Programs on File Handling

- Python Program to Read the Contents of the File
- Python Program to Copy One File to Another File
- Python Program to Count the Number of Lines in Text File
- Python Program to Count the Number of Blank Spaces in a Text File
- Python Program to Count the Occurrences of a Word in a Text File
- Python Program to Count the Number of Words in a Text File
- Python Program to Capitalize First Letter of Each Word in a File
- Python Program to Counts the Number of Times a Letter Appears in the Text File
- Python Program to Extract Numbers from Text File
- Python Program to Print the Contents of File in Reverse Order
- Python Program to Append the Content of One File to the End of Another File
- Python Program to Read a String from the User and Append it into a File

## Python Programming Examples on List

- Python Program to Find Largest Number in a List
- Python Program to Find Second Largest Number in a List
- Python Program to Print Largest Even and Largest Odd Number in a List
- Python Program to Split Even and Odd Elements into Two Lists
- Python Program to Find Average of a List
- Python Program to Print Sum of Negative Numbers, Positive Even & Odd Numbers in a List
- Python Program to Count Occurrences of Element in List
- Python Program to Find the Sum of Elements in a List using Recursion
- Python Program to Find the Length of a List using Recursion
- Python Program to Merge Two Lists and Sort it
- Python Program to Remove Duplicates from a List
- Python Program to Swap the First and Last Element in a List
- Python Program to Sort a List According to the Second Element in Sublist
- Python Program to Return the Length of the Longest Word from the List of Words
- Python Program to Find the Number Occurring Odd Number of Times in a List
- Python Program to Generate Random Numbers from 1 to 20 and Append Them to the List
- Python Program to Remove the ith Occurrence of the Given Word in a List
- Python Program to Find the Cumulative Sum of a List
- Python Program to Find the Union of Two Lists
- Python Program to Find the Intersection of Two Lists
- Python Program to Flatten a List without using Recursion
- Python Program to Find the Total Sum of a Nested List Using Recursion
- Python Program to Flatten a Nested List using Recursion

## Python Programs on Linked List

- Python Program to Create and Display Linked List
- Python Program to Remove Duplicates from a Linked List
- Python Program to Check if Two Linked Lists are Equal
- Python Program to Solve Josephus Problem using Linked List
- Python Program to Find Nth Node from End of Linked List
- Python Program to Swap Two Elements of the List without Key Field

More Python Programming Examples on Linked List

## Python Programs on Singly Linked List

- Python Program to Perform Singly Linked List Operations
- Python Program to Demonstrate Circular Single Linked List
- Python Program to Check if Singly Linked List is Palindrome
- Python Program to Convert Singly Linked List to Circular List

advertisement

## Python Programs on Doubly Linked List

- Python Program to Implement Circular Doubly Linked List
- Python Program to Find the Largest Element in a Doubly Linked List
- Python Program to Implement Doubly Linked List Operations

## Python Programs on Stack

- Python Program to Implement Stack
- Python Program to Implement Stack using Queue
- Python Program to Implement Stack using Two Queues
- Python Program to Reverse a Stack using Recursion
- Python Program to Check String is Palindrome using Stack
- Python Program to Check Expression is Correctly Parenthesized

## Python Programming Examples on Queue

- Python Program to Implement Queue
- Python Program to Implement Dequeue
- Python Program to Implement Queues using Stack

## Python Programs on Tree

- Python Program to Implement Binomial Tree
- Python Program to Construct a Tree and Perform Tree Operations
- Python Program to Count the Number of Nodes in Binary Tree
- Python Program to Display Tree Nodes using BFS Traversal
- Python Program to Find Nth Node of Inorder Traversal
- Python Program for Depth First Binary Tree Search using Recursion

More Python Programming Examples on Trees

## Python Programming Examples on Heap

- Python Program to Implement Binary Heap
- Python Program to Implement Binomial Heap
- Python Program to Implement Fibonacci Heap
- Python Program to Implement D-ary Heap
- Python Program to Implement Ternary Heap

## Python Programs on Graph

- Python Program to Implement Graph
- Python Program to Check the Connectivity of Undirected Graph Using BFS
- Python Program to Find Minimum Spanning Tree using Kruskal’s Algorithm
- Python Program to Find Minimum Spanning Tree using Prim’s Algorithm
- Python Program to Implement Dijkstra’s Shortest Path Algorithm
- Python Program to Implement Bellman Ford Algorithm
- Python Program to Implement Floyd Warshall Algorithm
- Python Program to Implement Johnson’s Algorithm
- Python Program to Check if Undirected Graph is Bipartite using BFS
- Python Program to Check if Undirected Graph is Bipartite using DFS

More Python Programming Examples on Graph

## Python Programs on Searching

- Python Program to Implement Linear Search
- Python Program to Perform Binary Search using Recursion
- Python Program to Find ith Smallest Element from List in Linear Time
- Python Program to Find ith Largest Element from List in Linear Time
- Python Program to Solve Maximum Subarray Problem using Divide and Conquer
- Python Program to Solve Maximum Subarray Problem using Kadane’s Algorithm

More Python Programming Examples on Searching

## Python Programs on Sorting

- Python Program to Implement Insertion Sort
- Python Program to Implement Selection Sort
- Python Program to Implement Bubble Sort
- Python Program to Implement Merge Sort
- Python Program to Implement Quick sort
- Python Program to Implement Comb Sort
- Python Program to Implement Radix Sort
- Python Program to Sort a List According to the Length of the Elements

More Python Programming Examples on Sorting

## Python Programs on Gaming

- Python Program to Demonstrate Tower Of Hanoi
- Python Program to Solve the Celebrity Problem
- Python Program to Solve n-Queen Problem with Recursion
- Python Program to Solve n-Queen Problem without Recursion

## Python Programs on Greedy Algorithms

- Python Program to Solve Fractional Knapsack Problem using Greedy Algorithm
- Python Program to Solve Interval Scheduling Problem using Greedy Algorithm
- Python Program to Find the Smallest Set of Unit-Length Closed Intervals using Greedy Algorithm
- Python Program to Minimize Lateness using Greedy Algorithm

## Python Programs on Dynamic Programming

- Python Program to Print nth Fibonacci Number using Dynamic Programming with Memoization
- Python Program to Print nth Fibonacci Number using DP with Bottom-Up Approach
- Python Program to Solve Rod Cutting Problem using Dynamic Programming with Memoization
- Python Program to Solve Rod Cutting Problem using DP with Bottom-Up Approach
- Python Program to Solve 0-1 Knapsack Problem using DP with Memoization
- Python Program to Solve 0-1 Knapsack Problem using DP with Bottom-Up Approach
- Python Program to Solve Matrix-Chain Multiplication using DP with Memoization
- Python Program to Solve Matrix-Chain Multiplication using DP with Bottom-Up Approach
- Python Program to Find Longest Common Subsequence using Dynamic Programming with Memoization
- Python Program to Find Longest Common Subsequence using Dynamic Programming with Bottom-Up Approach
- Python Program to Find Longest Common Substring using Dynamic Programming with Memoization
- Python Program to Find Longest Common Substring using Dynamic Programming with Bottom-Up Approach
- Python Program to Count all Paths in a Grid with Holes using Dynamic Programming with Memoization
- Python Program to Count all Paths in a Grid with Holes using Dynamic Programming with Bottom-Up Approach

**Additional Resources:**

- Linked List Programs in Python
- Python Programs on Trees
- C Programming Examples
- Python Programs on Graphs
- C Programs on Recursion

**Popular Pages:**