Open In App

Python Programs

Last Updated : 27 Dec, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

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 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. Find sum of array
  2. Find largest element in an array
  3. Program for 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

List Programs

Explore the below section and try out all the important Python List programming examples.

  1. Interchange first and last elements in a list
  2. Swap two elements in a list
  3. Ways to find length of list
  4. Ways to check if element exists in list
  5. Different ways to clear a list
  6. Reversing a List
  7. Find sum of elements in list
  8. Multiply all numbers in the list
  9. Find smallest number in a list
  10. Find largest number in a list
  11. Find second largest number in a list
  12. Find N largest elements from a list
  13. Even numbers in a list
  14. Odd numbers in a List
  15. Print all even numbers in a range
  16. Print all odd numbers in a range
  17. Print positive numbers in a list
  18. Print negative numbers in a list
  19. Print all positive numbers in a range
  20. Print all negative numbers in a range
  21. Remove multiple elements from a list
  22. Remove empty List from List
  23. Cloning or Copying a list
  24. Count occurrences of an element in a list
  25. Remove empty tuples from a list
  26. Print duplicates from a list of integers
  27. Find Cumulative sum of a list
  28. Sum of number digits in List
  29. Break a list into chunks of size N
  30. Sort the values of first list using second list
  31. More >>

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
  31. More >>

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
    More >>

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

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.


Practice Tags :

Similar Reads

three90RightbarBannerImg