Open In App

Python Programs

Last Updated : 13 Jun, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Python Examples:

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.

Python Programming Examples

So, without wasting your time start exploring the Python programs and scale up your logical abilities in Python program.

Python Programming Examples Topics :

Basic 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. Python program to add two numbers
  2. Maximum of two numbers in Python
  3. Python Program for factorial of a number
  4. Python Program for simple interest
  5. Python Program for compound interest
  6. Python Program to check Armstrong Number
  7. Python Program for Program to find area of a circle
  8. Python program to print all Prime numbers in an Interval
  9. Python program to check whether a number is Prime or not
  10. Python Program for n-th Fibonacci number
  11. Python Program for How to check if a given number is Fibonacci number?
  12. Python Program for n\’th multiple of a number in Fibonacci Series
  13. Program to print ASCII Value of a character
  14. Python Program for Sum of squares of first n natural numbers
  15. Python Program for 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 examples that are related to the Python array concept.

  1. Python Program to find sum of array
  2. Python Program to find largest element in an array
  3. Python Program for array rotation
  4. Python Program for Reversal algorithm for array rotation
  5. Python Program to Split the array and add the first part to the end
  6. Python Program for Find reminder of array multiplication divided by n
  7. Python Program to check if given array is Monotonic

List Programs:

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

  1. Python program to interchange first and last elements in a list
  2. Python program to swap two elements in a list
  3. Python | Ways to find length of list
  4. Python | Ways to check if element exists in list
  5. Different ways to clear a list in Python
  6. Python | Reversing a List
  7. Python program to find sum of elements in list
  8. Python | Multiply all numbers in the list
  9. Python program to find smallest number in a list
  10. Python program to find largest number in a list
  11. Python program to find second largest number in a list
  12. Python program to find N largest elements from a list
  13. Python program to print even numbers in a list
  14. Python program to print odd numbers in a List
  15. Python program to print all even numbers in a range
  16. Python program to print all odd numbers in a range
  17. Python program to print positive numbers in a list
  18. Python program to print negative numbers in a list
  19. Python program to print all positive numbers in a range
  20. Python program to print all negative numbers in a range
  21. Remove multiple elements from a list in Python
  22. Python – Remove empty List from List
  23. Python | Cloning or Copying a list
  24. Python | Count occurrences of an element in a list
  25. Python | Remove empty tuples from a list
  26. Python | Program to print duplicates from a list of integers
  27. Python program to find Cumulative sum of a list
  28. Python | Sum of number digits in List
  29. Break a list into chunks of size N in Python
  30. Python | 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. Python program to add two Matrices
  2. Python program to multiply two matrices
  3. Python program for Matrix Product
  4. Adding and Subtracting Matrices in Python
  5. Transpose a matrix in Single line in Python
  6. Python | Matrix creation of n*n
  7. Python | Get Kth Column of Matrix
  8. Python – 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. Python program to check if a string is palindrome or not
  2. Python program to check whether the string is Symmetrical or Palindrome
  3. Reverse words in a given String in Python
  4. Ways to remove i’th character from string in Python
  5. Python | Check if a Substring is Present in a Given String
  6. Python – Words Frequency in String Shorthands
  7. Python – Convert Snake case to Pascal case
  8. Find length of a string in python (4 ways)
  9. Python program to print even length words in a string
  10. Python program to accept the strings which contains all vowels
  11. Python | Count the Number of matching characters in a pair of string
  12. Remove all duplicates from a given string in Python
  13. Python – Least Frequent Character in String
  14. Python | Maximum frequency character in String
  15. Python | Program to 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. Python program for removing i-th character from a string
  19. Python program to split and join a string
  20. Python | Check if a given string is binary string or not
  21. Python program to find uncommon words from two Strings
  22. Python – Replace duplicate Occurrence in String
  23. Python – Replace multiple words with K
  24. Python | Permutation of a given string using inbuilt function
  25. Python | Check for URL in a String
  26. Execute a String of Code in Python
  27. String slicing in Python to rotate a string
  28. String slicing in Python to check if a string can become empty by recursive deletion
  29. Python Counter| Find all duplicate characters in string
  30. Python – 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. Python – Extract Unique values dictionary values
  2. Python program to find the sum of all items in a dictionary
  3. Python | Ways to remove a key from dictionary
  4. Ways to sort list of dictionaries by values in Python – Using itemgetter
  5. Ways to sort list of dictionaries by values in Python – Using lambda function
  6. Python | Merging two Dictionaries
  7. Python – Convert key-values list to flat dictionary
  8. Python – Insertion at the beginning in OrderedDict
  9. Python | Check order of character in string using OrderedDict( )
  10. Dictionary and counter in Python to find winner of election
  11. Python – Append Dictionary Keys and Values ( In order ) in dictionary
  12. Python | Sort Python Dictionaries by Key or Value
  13. Python – Sort Dictionary key and values List
  14. Handling missing keys in Python dictionaries
  15. Python dictionary with keys having multiple inputs
  16. Print anagrams together in Python using List and Dictionary
  17. K’th Non-repeating Character in Python using List Comprehension and OrderedDict
  18. Check if binary representations of two numbers are anagram
  19. Python Counter to find the size of largest subset of anagram words
  20. Python | Remove all duplicates words from a given sentence
  21. Python Dictionary to find mirror characters in a string
  22. Counting the frequencies in a list using dictionary in Python
  23. Python | Convert a list of Tuples into Dictionary
  24. Python counter and dictionary intersection example (Make a string using deletion and rearrangement)
  25. Python dictionary, set and counter to check if frequencies can become same
  26. Scraping And Finding Ordered Words In A Dictionary using Python
  27. Possible Words using given characters in Python
  28. Python – 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. Python program to Find the size of a Tuple
  2. Python – 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. Python – Adding Tuple to List and vice – versa
  5. Python – Closest Pair to Kth index element in Tuple
  6. Python – Join Tuples if similar initial element
  7. Python – Extract digits from Tuple list
  8. Python – All pair combinations of 2 tuples
  9. Python – Remove Tuples of Length K
  10. Sort a list of tuples by second Item
  11. Python program to Order Tuples using external List
  12. Python – Flatten tuple of List to tuple
  13. Python – Convert Nested Tuple to Custom Key Dictionary
  14. More >>

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. Python Program for Binary Search (Recursive and Iterative)
  2. Python Program for Linear Search
  3. Python Program for Insertion Sort
  4. Python Program for Recursive Insertion Sort
  5. Python Program for QuickSort
  6. Python Program for Iterative Quick Sort
  7. Python Program for Selection Sort
  8. Python Program for Bubble Sort
  9. Python Program for Merge Sort
  10. Python Program for Iterative Merge Sort
  11. Python Program for Heap Sort
  12. Python Program for Counting Sort
  13. Python Program for ShellSort
  14. Python Program for Topological Sorting
  15. Python Program for Radix Sort
  16. Python Program for Binary Insertion Sort
  17. Python Program for Bitonic Sort
  18. Python Program for Comb Sort
  19. Python Program for Pigeonhole Sort
  20. Python Program for Cocktail Sort
  21. Python Program for Gnome Sort
  22. Python Program for Odd-Even Sort / Brick Sort
  23. Python Program for BogoSort or Permutation Sort
  24. Python Program for Cycle Sort
  25. Python Program for Stooge Sort

Pattern Printing Programs:

Get a complete list of Python pattern printing examples in the below section.

  1. Python Program to print the pattern ‘G’
  2. Python Program to print an Inverted Star Pattern
  3. Python Program to print double sided stair-case pattern
  4. Python Program to 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. Python program to get Current Time
  2. Get Current Date and Time using Python
  3. Python | Find yesterday’s, today’s and tomorrow’s date
  4. Python program to convert time from 12 hour to 24 hour format
  5. Python program to find difference between current time and given time
  6. Python Program to Create a Lap Timer
  7. Convert date string to timestamp in Python
  8. How to convert timestamp string to datetime object in Python?
  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. Python Program to Check if String Contain Only Defined Characters using Regex
  2. Python program to Count Uppercase, Lowercase, special character and numeric values using Regex
  3. Python Program to find the most occurring number in a string using Regex
  4. Python Regex to extract maximum numeric value from a string
  5. Python Program to put spaces between words starting with capital letters using Regex
  6. Python – Check whether a string starts and ends with the same character or not
  7. Python regex to find sequences of one upper case letter followed by lower case letters
  8. Python Program to Remove duplicate words from Sentence
  9. Python | Remove all characters except letters and numbers
  10. Python Regex | Program to accept string ending with alphanumeric character
  11. Python Regex – Program to accept string starting with vowel
  12. Python Program to check if a string starts with a substring using regex
  13. Python Program to Check if an URL is valid or not using Regular Expression
  14. Parsing and Processing URL using Python – Regex
  15. Python Program to validate an IP address using ReGex
  16. Python Program to Check if email address valid or not
  17. Python program to find files having a particular extension using RegEx
  18. Python program to extract IP address from file
  19. Python program to check the validity of a Password
  20. Categorize Password as Strong or Weak using Regex in Python

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. Python program to read file word by word
  2. Python program to read character by character from a file
  3. Python – Get number of characters, words, spaces and lines in a file
  4. Python program to Count the Number of occurrences of a key-value pair in a text file
  5. Python | Finding ‘n’ Character Words in a Text File
  6. Python Program to obtain the line number in which given word is present
  7. Count number of lines in a text file in Python
  8. Python Program to remove lines starting with any prefix
  9. Python Program to Eliminate repeated lines from a file
  10. Python Program to read List of Dictionaries from File
  11. Python – Append content of one text file to another
  12. Python program to copy odd lines of one file to other
  13. Python Program to merge two files into a third file
  14. Python program to Reverse a single line of a text file
  15. Python program to reverse the content of a file and store it in another file
  16. Python Program to 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. Python Program to Reverse a linked list
  2. Python Program for Find largest prime factor of a number
  3. Python Program for Efficient program to print all prime factors of a given number
  4. Python Program for Product of unique prime factors of a number
  5. Python Program for Find sum of odd factors of a number
  6. Python Program for Coin Change
  7. Python Program for Tower of Hanoi
  8. Python Program for Sieve of Eratosthenes
  9. Python Program to Check if binary representation is palindrome
  10. Python Program for Basic Euclidean algorithms
  11. Python Program for Extended Euclidean algorithms
  12. Python Program for Maximum height when coins are arranged in a triangle
  13. Python Program for Find minimum sum of factors of number
  14. Python Program for Difference between sums of odd and even digits
  15. Python Program for Program to Print Matrix in Z form
  16. Python Program for Smallest K digit number divisible by X
  17. Python Program for Print Number series without using any loop
  18. Python Program for Number of stopping station problem
  19. Check if a triangle of positive area is possible with the given angles
  20. Python program to find the most occurring character and its count
  21. Python Program for Find sum of even factors of a number
  22. Python Program for 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. Python Program for Number of solutions to Modular Equations
  25. Python Program for Legendre\’s Conjecture


Previous Article
Next Article

Similar Reads

Output of Python Programs | Set 22 (Loops)
Prerequisite: Loops Note: Output of all these programs is tested on Python3 1. What is the output of the following? mylist = ['geeks', 'forgeeks'] for i in mylist: i.upper() print(mylist) [‘GEEKS’, ‘FORGEEKS’]. [‘geeks’, ‘forgeeks’]. [None, None]. Unexpected Output: 2. [‘geeks’, ‘forgeeks’] Explanation: The function upper() does not modify a string
2 min read
Output of Python Programs | Set 24 (Dictionary)
Prerequisite : Python-Dictionary 1. What will be the output? dictionary = {"geek":10, "for":45, "geeks": 90} print("geek" in dictionary) Options: 10 False True Error Output: 3. True Explanation: in is used to check the key exist in dictionary or not. 2. What will be the output? dictionary ={1:"geek"
2 min read
Using lambda in GUI programs in Python
Python Lambda Functions are anonymous function means that the function is without a name. In this article, we will learn to use lambda functions in Tkinter GUI. We use lambda functions to write our code more efficiently and to use one function many times by passing different arguments. We use the lambda function to pass arguments to other functions
3 min read
Output of Python Programs | (Dictionary)
Prerequisite: Dictionary Note: Output of all these programs is tested on Python3 1.What is the output of the following of code? a = {i: i * i for i in range(6)} print (a) Options: a) Dictionary comprehension doesn’t exist b) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36} c) {0: 0, 1: 1, 4: 4, 9: 9, 16: 16, 25: 25} d) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5
2 min read
Structuring Python Programs
In this article, you would come to know about proper structuring and formatting your python programs. Python Statements In general, the interpreter reads and executes the statements line by line i.e sequentially. Though, there are some statements that can alter this behavior like conditional statements. Mostly, python statements are written in such
7 min read
Output of Python programs | Set 7
Prerequisite - Strings in Python Predict the output of the following Python programs. These question set will make you conversant with String Concepts in Python programming language. Program 1 var1 = 'Hello Geeks!' var2 = "GeeksforGeeks" print "var1[0]: ", var1[0] # statement 1 print "var2[1:5]: ", var2[1:5] # statemen
3 min read
Output of Python programs | Set 8
Prerequisite - Lists in Python Predict the output of the following Python programs. Program 1 Python Code list = [1, 2, 3, None, (1, 2, 3, 4, 5), ['Geeks', 'for', 'Geeks']] print len(list) Output: 6Explanation: The beauty of python list datatype is that within a list, a programmer can nest another list, a dictionary or a tuple. Since in the code th
3 min read
Output of Python programs | Set 9 (Dictionary)
Prerequisite: Dictionary 1) What is the output of the following program? C/C++ Code dictionary = {'GFG' : 'geeksforgeeks.org', 'google' : 'google.com', 'facebook' : 'facebook.com' } del dictionary['google']; for key, values in dictionary.items(): print(key) dictionary.clear(); for key, values in dictionary.items(): print(key) del dictionary; for ke
3 min read
Output of Python programs | Set 10 (Exception Handling)
Pre-requisite: Exception Handling in Python Note: All the programs run on python version 3 and above. 1) What is the output of the following program? data = 50 try: data = data/0 except ZeroDivisionError: print('Cannot divide by 0 ', end = '') else: print('Division successful ', end = '') try: data = data/5 except: print('Inside except block ', end
3 min read
Output of Python Programs | Set 18 (List and Tuples)
1) What is the output of the following program? C/C++ Code L = list('123456') L[0] = L[5] = 0 L[3] = L[-2] print(L) a) [0, '2', '3', '4', '5', 0] b) ['6', '2', '3', '5', '5', '6'] c) ['0', '2', '3', '5', '5', '0'] d) [0, '2', '3', '5', '5', 0] Ans. (d) Explanation: L[0] is '1' and L[5] is '6', both of these elements will be replaced by 0 in the Lis
3 min read
Practice Tags :
three90RightbarBannerImg