Skip to content
    geeksforgeeks
    • Interview Prep
      • DSA
      • Interview Corner
      • Aptitude & Reasoning
      • Practice Coding Problems
      • All Courses
    • Tutorials
      • Python
      • Java
      • ML & Data Science
      • Programming Languages
      • Web Development
      • CS Subjects
      • DevOps
      • Software and Tools
      • School Learning
    • Tracks
      • Languages
        • Python
        • C
        • C++
        • Java
        • Advanced Java
        • SQL
        • JavaScript
        • C#
      • Interview Preparation
        • GfG 160
        • GfG 360
        • System Design
        • Core Subjects
        • Interview Questions
        • Interview Puzzles
        • Aptitude and Reasoning
        • Product Management
        • Computer Organisation and Architecture
      • Data Science
        • Python
        • Data Analytics
        • Complete Data Science
        • Gen AI
        • Agentic AI
      • Dev Skills
        • Full-Stack Web Dev
        • DevOps
        • Software Testing
        • CyberSecurity
        • NextJS
        • Git
      • Tools
        • Computer Fundamentals
        • AI Tools
        • MS Excel & Google Sheets
        • MS Word & Google Docs
      • Maths
        • Maths For Computer Science
        • Engineering Mathematics
        • School Maths
    • Python Tutorial
    • Data Types
    • Interview Questions
    • Examples
    • Quizzes
    • DSA Python
    • Data Science
    • NumPy
    • Pandas
    • Practice
    • Django
    • Flask
    • Projects
    Open In App

    Python Programs

    Last Updated : 25 Sep, 2025
    Comments
    Improve
    Suggest changes
    80 Likes
    Like
    Report

    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. Print all Prime numbers in an Interval
    9. Check whether a number is Prime or not
    10. N-th Fibonacci number
    11. Check if a given number is Fibonacci number?
    12. Nth multiple of a number in Fibonacci Series
    13. Print ASCII Value of a character
    14. Sum of squares of first n natural numbers
    15. Cube sum of first n natural numbers
    Python Programming Examples

    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. Sum of array
    2. Largest element in an array
    3. Array rotation
    4. Reversal algorithm for array rotation
    5. Split the array and add the first part to the end
    6. Find reminder of array multiplication divided by n
    7. Check if given array is Monotonic
    8. Interchange first and last elements in a list
    9. Swap two elements in a list
    10. Ways to find length of list
    11. Ways to check if element exists in list
    12. Different ways to clear a list
    13. Reversing a List
    14. Find sum of elements in list
    15. Multiply all numbers in the list
    16. Find smallest number in a list
    17. Find largest number in a list
    18. Find second largest number in a list
    19. Find N largest elements from a list
    20. Even numbers in a list
    21. Odd numbers in a List
    22. Print all even numbers in a range
    23. Print all odd numbers in a range
    24. Print positive numbers in a list
    25. Print negative numbers in a list
    26. Print all positive numbers in a range
    27. Print all negative numbers in a range
    28. Remove multiple elements from a list
    29. Remove empty List from List
    30. Cloning or Copying a list
    31. Count occurrences of an element in a list
    32. Remove empty tuples from a list
    33. Print duplicates from a list of integers
    34. Find Cumulative sum of a list
    35. Sum of number digits in List
    36. Break a list into chunks of size N
    37. 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. Transpose a matrix in Single line
    6. Matrix creation of n*n
    7. Get Kth Column of Matrix
    8. 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. Check whether the string is Symmetrical or Palindrome
    3. Reverse words in a given String
    4. Ways to remove i’th character from string
    5. Check if a Substring is Present in a Given String
    6. Words Frequency in String Shorthands
    7. Convert Snake case to Pascal case
    8. Find length of a string (4 ways)
    9. Print even length words in a string
    10. Accept the strings which contains all vowels
    11. Count the Number of matching characters in a pair of string
    12. Remove all duplicates from a given string
    13. Least Frequent Character in String
    14. Maximum frequency character in String
    15. Check if a string contains any special character
    16. Generating random strings until a given string is generated
    17. Find words which are greater than given length k
    18. Removing i-th character from a string
    19. Split and join a string
    20. Check if a given string is binary string or not
    21. Find uncommon words from two Strings
    22. Replace duplicate Occurrence in String
    23. Replace multiple words with K
    24. Permutation of a given string using inbuilt function
    25. Check for URL in a String
    26. Execute a String of Code
    27. String slicing to rotate a string
    28. String slicing to check if a string can become empty by recursive deletion
    29. Counter| Find all duplicate characters in string
    30. 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. Ways to sort list of dictionaries by values Using itemgetter
    5. Ways to sort list of dictionaries by values Using lambda function
    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. Dictionary and counter to find winner of election
    11. Append Dictionary Keys and Values ( In order ) in dictionary
    12. Sort Python Dictionaries by Key or Value
    13. Sort Dictionary key and values List
    14. Handling missing keys in Python dictionaries
    15. Dictionary with keys having multiple inputs
    16. Print anagrams together using List and Dictionary
    17. K’th Non-repeating Character using List Comprehension and OrderedDict
    18. Check if binary representations of two numbers are anagram
    19. Counter to find the size of largest subset of anagram words
    20. Remove all duplicates words from a given sentence
    21. Dictionary to find mirror characters in a string
    22. Counting the frequencies in a list using dictionary
    23. Convert a list of Tuples into Dictionary
    24. Counter and dictionary intersection example (Make a string using deletion and rearrangement)
    25. Dictionary, set and counter to check if frequencies can become same
    26. Scraping And Finding Ordered Words In A Dictionary
    27. Possible Words using given characters
    28. 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 a list of tuples from given list having number and its cube in each tuple
    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 the pattern ‘G’
    2. Print an Inverted Star Pattern
    3. Print double sided stair-case pattern
    4. 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.

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

    1. Check if String Contain Only Defined Characters using Regex
    2. Count Uppercase, Lowercase, special character and numeric values using Regex
    3. Find the most occurring number in a string using Regex
    4. Regex to extract maximum numeric value from a string
    5. Program to put spaces between words starting with capital letters using Regex
    6. Check whether a string starts and ends with the same character or not
    7. Regex to find sequences of one upper case letter followed by lower case letters
    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 using regex
    13. Check if an URL is valid or not using Regular Expression
    14. Parsing and Processing URL – Regex
    15. Validate an IP address using ReGex
    16. Check if email address valid or not
    17. Find files having a particular extension using RegEx
    18. Extract IP address from file
    19. Check the validity of a Password
    20. 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.

    1. Read file word by word
    2. Read character by character from a file
    3. Get number of 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. Obtain the line number in which given word is present
    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

    More Popular Python Programs

    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. Program for Coin Change
    7. Program for Tower of Hanoi
    8. Sieve of Eratosthenes
    9. Check if binary representation is palindrome
    10. Basic Euclidean algorithms
    11. Extended Euclidean algorithms
    12. Maximum height when coins are arranged in a triangle
    13. Find minimum sum of factors of number
    14. Difference between sums of odd and even digits
    15. Print Matrix in Z form
    16. Smallest K digit number divisible by X
    17. Print Number series without using any loop
    18. Number of stopping station problem
    19. Check if a triangle of positive area is possible with the given angles
    20. Find the most occurring character and its count
    21. Find sum of even factors of a number
    22. Check if all digits of a number divide it
    23. Check whether a number has consecutive 0’s in the given base or not
    24. Number of solutions to Modular Equations
    25. Legendre’s Conjecture

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

    Create Quiz

    K

    kumar_satyam
    Improve

    K

    kumar_satyam
    Improve
    Article Tags :
    • Python
    • Python Programs
    • Tutorials

    Explore

      Python Fundamentals

      Python Introduction

      2 min read

      Input and Output in Python

      4 min read

      Python Variables

      4 min read

      Python Operators

      4 min read

      Python Keywords

      2 min read

      Python Data Types

      8 min read

      Conditional Statements in Python

      3 min read

      Loops in Python - For, While and Nested Loops

      5 min read

      Python Functions

      5 min read

      Recursion in Python

      4 min read

      Python Lambda Functions

      5 min read

      Python Data Structures

      Python String

      5 min read

      Python Lists

      4 min read

      Python Tuples

      4 min read

      Python Dictionary

      3 min read

      Python Sets

      6 min read

      Python Arrays

      7 min read

      List Comprehension in Python

      4 min read

      Advanced Python

      Python OOP Concepts

      11 min read

      Python Exception Handling

      5 min read

      File Handling in Python

      4 min read

      Python Database Tutorial

      4 min read

      Python MongoDB Tutorial

      3 min read

      Python MySQL

      9 min read

      Python Packages

      10 min read

      Python Modules

      3 min read

      Python DSA Libraries

      15 min read

      List of Python GUI Library and Packages

      3 min read

      Data Science with Python

      NumPy Tutorial - Python Library

      3 min read

      Pandas Tutorial

      4 min read

      Matplotlib Tutorial

      5 min read

      Python Seaborn Tutorial

      3 min read

      StatsModel Library - Tutorial

      3 min read

      Learning Model Building in Scikit-learn

      6 min read

      TensorFlow Tutorial

      2 min read

      PyTorch Tutorial

      6 min read

      Web Development with Python

      Flask Tutorial

      8 min read

      Django Tutorial | Learn Django Framework

      7 min read

      Django ORM - Inserting, Updating & Deleting Data

      4 min read

      Templating With Jinja2 in Flask

      6 min read

      Django Templates

      5 min read

      Build a REST API using Flask - Python

      3 min read

      Building a Simple API with Django REST Framework

      3 min read

      Python Practice

      Python Quiz

      1 min read

      Python Coding Practice

      1 min read

      Python Interview Questions and Answers

      15+ min read
    top_of_element && top_of_screen < bottom_of_element) || (bottom_of_screen > articleRecommendedTop && top_of_screen < articleRecommendedBottom) || (top_of_screen > articleRecommendedBottom)) { if (!isfollowingApiCall) { isfollowingApiCall = true; setTimeout(function(){ if (loginData && loginData.isLoggedIn) { if (loginData.userName !== $('#followAuthor').val()) { is_following(); } else { $('.profileCard-profile-picture').css('background-color', '#E7E7E7'); } } else { $('.follow-btn').removeClass('hideIt'); } }, 3000); } } }); } $(".accordion-header").click(function() { var arrowIcon = $(this).find('.bottom-arrow-icon'); arrowIcon.toggleClass('rotate180'); }); }); window.isReportArticle = false; function report_article(){ if (!loginData || !loginData.isLoggedIn) { const loginModalButton = $('.login-modal-btn') if (loginModalButton.length) { loginModalButton.click(); } return; } if(!window.isReportArticle){ //to add loader $('.report-loader').addClass('spinner'); jQuery('#report_modal_content').load(gfgSiteUrl+'wp-content/themes/iconic-one/report-modal.php', { PRACTICE_API_URL: practiceAPIURL, PRACTICE_URL:practiceURL },function(responseTxt, statusTxt, xhr){ if(statusTxt == "error"){ alert("Error: " + xhr.status + ": " + xhr.statusText); } }); }else{ window.scrollTo({ top: 0, behavior: 'smooth' }); $("#report_modal_content").show(); } } function closeShareModal() { const shareOption = document.querySelector('[data-gfg-action="share-article"]'); shareOption.classList.remove("hover_share_menu"); let shareModal = document.querySelector(".hover__share-modal-container"); shareModal && shareModal.remove(); } function openShareModal() { closeShareModal(); // Remove existing modal if any let shareModal = document.querySelector(".three_dot_dropdown_share"); shareModal.appendChild(Object.assign(document.createElement("div"), { className: "hover__share-modal-container" })); document.querySelector(".hover__share-modal-container").append( Object.assign(document.createElement('div'), { className: "share__modal" }), ); document.querySelector(".share__modal").append(Object.assign(document.createElement('h1'), { className: "share__modal-heading" }, { textContent: "Share to" })); const socialOptions = ["LinkedIn", "WhatsApp","Twitter", "Copy Link"]; socialOptions.forEach((socialOption) => { const socialContainer = Object.assign(document.createElement('div'), { className: "social__container" }); const icon = Object.assign(document.createElement("div"), { className: `share__icon share__${socialOption.split(" ").join("")}-icon` }); const socialText = Object.assign(document.createElement("span"), { className: "share__option-text" }, { textContent: `${socialOption}` }); const shareLink = (socialOption === "Copy Link") ? Object.assign(document.createElement('div'), { role: "button", className: "link-container CopyLink" }) : Object.assign(document.createElement('a'), { className: "link-container" }); if (socialOption === "LinkedIn") { shareLink.setAttribute('href', `https://www.linkedin.com/sharing/share-offsite/?url=${window.location.href}`); shareLink.setAttribute('target', '_blank'); } if (socialOption === "WhatsApp") { shareLink.setAttribute('href', `https://api.whatsapp.com/send?text=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } if (socialOption === "Twitter") { shareLink.setAttribute('href', `https://twitter.com/intent/tweet?url=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } shareLink.append(icon, socialText); socialContainer.append(shareLink); document.querySelector(".share__modal").appendChild(socialContainer); //adding copy url functionality if(socialOption === "Copy Link") { shareLink.addEventListener("click", function() { var tempInput = document.createElement("input"); tempInput.value = window.location.href; document.body.appendChild(tempInput); tempInput.select(); tempInput.setSelectionRange(0, 99999); // For mobile devices document.execCommand('copy'); document.body.removeChild(tempInput); this.querySelector(".share__option-text").textContent = "Copied" }) } }); // document.querySelector(".hover__share-modal-container").addEventListener("mouseover", () => document.querySelector('[data-gfg-action="share-article"]').classList.add("hover_share_menu")); } function toggleLikeElementVisibility(selector, show) { document.querySelector(`.${selector}`).style.display = show ? "block" : "none"; } function closeKebabMenu(){ document.getElementById("myDropdown").classList.toggle("show"); }
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Campus Training Program
  • Explore
  • POTD
  • Job-A-Thon
  • Blogs
  • Nation Skill Up
  • Tutorials
  • Programming Languages
  • DSA
  • Web Technology
  • AI, ML & Data Science
  • DevOps
  • CS Core Subjects
  • Interview Preparation
  • Software and Tools
  • Courses
  • ML and Data Science
  • DSA and Placements
  • Web Development
  • Programming Languages
  • DevOps & Cloud
  • GATE
  • Trending Technologies
  • Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
  • Preparation Corner
  • Interview Corner
  • Aptitude
  • Puzzles
  • GfG 160
  • System Design
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.
See More

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences