Python Programming Exercises and Solutions
Python Programming Exercises
and Solutions
Here you will find all the questions and answers related to Python
programming exercises. The table below provides a list of Python
exercises for beginners. The exercises are categorized as follows:
List of Python Exercises and Solutions
Basic Program
Sum of Two Numbers in Python
Multiplication Table in Python
Subtract Two Numbers in Python
Division of Two Numbers in Python
Multiplication of Two Numbers in Python
Min and Max Numbers Using a User-defined Function in Python
Minimum and Maximum of a List of Numbers in Python
Generate a Random Number in Python
Convert Kilometers to Miles in Python
Print Output Without a Newline in Python
Python Program to Make a Simple Calculator
Create Calculator Using Eval in Python
Object Oriented
Get the Class Name of an Instance in Python
Differentiate Between Type() and Isinstance() in Python
Functio
ns Display Powers of 2 Upto N Numbers in Python
Display Powers of 2 Using Normal Function in Python
Display Powers of 2 Using Anonymous Function in Python
Find Numbers Divisible by Another Number in Python
Convert Decimal to Binary, Octal and Hexadecimal in Python
Find Ascii Value of Character in Python
Shuffle Deck of Cards in Python
Display Calendar in Python
Gcd of Two Numbers in Python Using Recursion
Gcd of Two Numbers in Python Using in-build Function
Lcm of Two Numbers in Python Using While Loop
Lcm of Two Numbers in Python Using Recursion
Find Sum of Natural Numbers in Python Using Recursion
Find Factorial of Number in Python Using Recursion
Convert Decimal to Binary in Python Using Recursion
Return Multiple Values From a Function in Python
Temperature Conversion Program in Python
Quadratic Equation in Python Without Lambda
Leap Year Program In Python
Leap Year Program in Python Using If Else
Check Leap year from Logical operator in a single line in Python
Pre-defined Function to Check Leap Year in Python
Convert Binary to Decimal in Python
Pascal Triangle In Python
Pascal Triangle In Python Using the Powers of 11
Decision Making and Loops
Factorial of the Number in Python Using in-built Function
Factorial of the Number in Python Using While Loop
Factorial of the Number in Python Using for Loop
Factorial of a Number in Python Using Recursion
Check if a Number is Positive, Negative or 0 in Python
Find the Largest Among Three Numbers in Python
Print All Prime Numbers in a Range Using Python
Print the Fibonacci Sequence in Python Using While Loop
Print the Fibonacci Sequence in Python Using for Loop
Display Fibonacci Sequence in Python Using Recursion
Check Armstrong Number in Python Using Function
Check Armstrong Number in Python Using Recursion
Find the Sum of Natural Numbers in Python
Iterate Over Dictionaries in Python Using Keys() Function
Iterate Over Dictionaries in Python Using for Loop
Iterate Over Dictionaries in Python Using Values() Function
Iterate Over Dictionaries in Python Using Items() Function
Iterate Over Dictionaries in Python Using Both Key() & Value()
Function
Iterate Over Dictionaries in Python and Print Items in Key-value
in
Pair
Iterate Over Dictionaries in Python & Unpack the Dictionaries
Reverse a Number in Python Using for Loop
Reverse a Number in Python Using While Loop
Reverse a Number in Python Using String Slicing
Reverse a Number in Python Using Recursion
Compute the Power of a Number in Python
Star Pattern in Python Using Loops in Python
Printing Number Patterns in Python
Alphabet Pattern Programs in Python
Count Vowels in a String Python in Python
Count Vowels From a String In Python Using Comprehension
Method
Count Vowels From a String In Python Using Recursive Method
Count Vowels From a String in Python Using Iterative Method
Count Alphabets in a String in Python
Native Data
typeAdsd Two Matrices in Python
Transpose a Matrix in Python
Multiply Two Matrices in Python
Check Whether a String is Palindrome or Not in Python
Remove Punctuations From a String in Python
Remove Punctuations From a String in Python Using String Package
Remove Punctuations From a String in Python Using Regular
Expressions
Sort Words in Alphabetic Order in Python
Illustrate Different Set Operations in Python
Merge Two Dictionaries in Python
Access Index of a List in Python Using for Loop
Flatten a Nested List in Python Using a List Comprehension
Flatten a Nested List in Python Using Nested for Loops
Flatten a Nested List in Python Using Itertools Package
Flatten a Nested List in Python Using in-build Sum() Method
Flatten a Nested List in Python Using Lambda and Reduce()
Slice Lists in Python
Sort a Dictionary by Value in Python
Check if a List is Empty or Not in Python
Check if a List is Empty or Not in Python Using Len() Function
Check if a List is Empty or Not in Python by Comparing an Empty
List
Check if a List is Empty or Not in Python Using _len_()
Check if a List is Empty or Not in Python Using Numpy Module
Concatenate Two Lists Using + Operator in Python
Concatenate Two Lists Using Iterable Unpacking Operator * in Python
Concatenate Two Lists With Unique Values in Python
Concatenate Two Lists Using Extend() in Python
Check if a Key is Already Present in a Dictionary Using in Keyword in
Python
Check if a Key is Already Present in a Dictionary Using Get() in
Python
Check if Key Exists in Dictionary Python Using Keys()
Check if a Key is Already Present in a Dictionary Using Count()
Method in Python
Split a List Into Evenly Sized Chunks in Python Using Yield
Split a List Into Evenly Sized Chunks in Python Using for Loop
Split a List Into Evenly Sized Chunks in Python Using List
Comprehension
Split a List Into Evenly Sized Chunks in Python Using
Numpy
Split a List Into Evenly Sized Chunks in Python Using
itertool
Split a List Into Evenly Sized Chunks in Python Using
Collections
Split a List Into Evenly Sized Chunks Using Partial assignment in
python
Convert String to Float in Python
Convert String Float Numeral Into Float in Python
Convert a String Into an Integer in Python
Convert a String Float Numeral Into an Integer in Python
Print Colored Text to the Terminal in Python
Convert String to Date time in Python
Find the Last Element of a List in Python Using Negative Indexing
Find the Last Element of a List in Python Using Slicing
Find the Last Element of a List in Python Using pop() Function
Find the Last Element of a List in Python Using for Loop
Get a Substring of a String in Python
Randomly Select Element From List in Python Using randrange()
Randomly Select Element From List in Python Using sample()
Randomly Select Element From List in Python Using choices()
Check if a String is a Number (Float) in Python
Count Occurrences of Items in a Python List Using Loop
Count Occurrences of Items in a Python List Using count()
Count Occurrences of Items in a Python List Using counter()
Count Occurrences of Items in a Python List Using countof()
Count Occurrences of Items in a Python List Using Comprehension
Count Occurrences of Items in a Python List Using Pandas Library
Delete an Element From a Dictionary in Python Using Del
Statement
Delete an Element From a Dictionary in Python Using clear()
Create a Long Multiline String in Python Using Triple Quotes
Create a Long Multiline String in Python Using Parentheses &
Single/Double Quotes
Create a Long Multiline String in Python Using \ (Backslash)
Convert Two Lists Into a Dictionary in Python Using for Loop
Convert Two Lists Into a Dictionary in Python Using Dictionary
Comprehension
Convert Two Lists Into a Dictionary in Python Using zip() Function
Convert Two Lists Into a Dictionary in Python Using map()
Function
Convert Two Lists Into a Dictionary in Python Using enumerate()
Function
Remove Whitespace From String in Python Using strip() Function
Remove Whitespace From String in Python Using Regular
Expression
Iterate Through Two Lists in Parallel Python Using zip()
Iterate Through Two Lists in Parallel Python Using itertools
Iterate Through Two Lists in Parallel Python Using
itertools.zip_longest()
Count Number of Digits in a Number in Python
Using While Loop
Count Number of Digits in a Number in Python
Using inbuilt Method
Check if Two Strings Are Anagrams in Python Using
sorted() Function
Check if Two Strings Are Anagrams in Python Using
counter()
Check if Two Strings are Anagrams in Python Using
sort()
Capitalize the First Character of a String in Python
Using capitalize()
Capitalize the First Character of a String in Python
Using upper()
Capitalize the First Character of a String in Python
Using str.title()
Capitalize the First Letter of Each Word in Python
Using capitalize()
Capitalize the First Letter of Each Word in Python Using
string.capwords()
Capitalize the First Letter of Each Word in Python Using
RegExp
Capitalize the First Letter of Each Word in Python Using
title()
Capitalize the First Letter of Every Word in the File Using title() in
Python
Find All the Permutation of a String in Python Using a Naive Method
Find All the Permutation of a String in Python Using itertools
Count the Number of Occurrence of a Character in String Using
Python
Count the Number of Occurrences of a Character in a String in
Python Using count()
Remove Duplicate Elements From a List in Python Using *set()
Remove Duplicate Elements From a List in Python Using list
comprehension
Remove Duplicate Elements From a List in Python Using set()
Remove Duplicate Elements From a List in Python Using list
comprehension
Remove Duplicate Elements From a List in Python Using set()
Remove Duplicate Elements From a List in Python Using
enumerate()
Remove Duplicate Elements From a List in Python Using
OrderedDict.fromkeys()
Remove Duplicate Elements From a List in Python Using in, not in
Operators
Remove Duplicate Elements From a List in Python Using
Array.index()
Remove Duplicate Elements From a List in Python Using Counter()
Remove Duplicate Elements From a List in Python Using numpy
Merge Lists in Python
File
s Copy a File in Python
Append to a File in Python
Find Hash of File in Python
Get the File Name From the File Path in Python
Get Line Count of a File in Python
Check the File Size in Python
Catch Multiple Exceptions in One Line in Python
Python Program Read a File Line by Line Into a List in Python
Find the Size (Resolution) of an Image in Python
Get Extension of File in Python
List All Txt Files in a Directory in Python
Get File Creation and Modification Date in Python
Current Working Directory in Python
Advanced
Enum in Python
Create a Countdown Timer in Python
Convert Bytes to a String in Python
Python Programming Exercises and
Solutions for Beginners
The importance of Python Programming Exercises and Solutions for
beginners and experienced programmers are equally vital. With the
help of these activities, you can broaden your intellectual horizons,
sharpen your technological abilities, and prepare for job
applications.
Exercises are an important instrument to help you better your
coding abilities, acquire confidence, and prepare for real-world
scenarios.
Comments