Top 100+ Python Interview & Practice Questions
A complete list of Python programming questions covering Operators, Conditional Statements, Loops, Functions, Lists, Sets, Strings, Tuples, Dictionaries, OOP, and Exception Handling.
Operators
- Write a program to swap two numbers using bitwise XOR.
- Implement a calculator using arithmetic operators (+, -, *, /, %).
- Find whether a number is even or odd using bitwise operators.
- Implement a program to check if two numbers are equal without using comparison operators (== or !=).
- Find the remainder without using the modulo (%) operator.
- Write a program to check if a number is a power of 2 using bitwise operators.
- Use ternary operators to find the maximum of three numbers.
- Implement a program to count the number of 1s in a binary representation of a number.
- Write a program to swap two numbers without using a third variable.
- Use logical operators to check if a number is within a given range.
Conditional Statements
- Check whether a given year is a leap year or not.
- Write a program to determine if a number is positive, negative, or zero.
- Find the greatest of three numbers using nested if statements.
- Implement a grading system where marks are input, and the program prints grades accordingly.
- Write a menu-driven program for a simple calculator using if-elif.
- Check if a character is a vowel or consonant.
- Determine whether a triangle is equilateral, isosceles, or scalene based on given sides.
- Write a program to find whether a number is divisible by both 3 and 5.
- Implement a simple ATM withdrawal system with conditions.
- Check whether a number is prime or not using conditional statements.
Looping Statements
- Print the Fibonacci series up to n terms.
- Print all prime numbers within a given range.
- Write a program to reverse a number.
- Print a multiplication table of a given number.
- Find the sum of digits of a given number.
- Write a program to check if a number is an Armstrong number.
- Count the number of vowels and consonants in a string.
- Print a pattern like a pyramid using nested loops.
- Find the factorial of a number using a loop.
- Implement a number guessing game using a loop.
Functions
- Write a function to calculate the factorial of a number.
- Implement a function to check if a number is prime.
- Write a function to find the largest of three numbers.
- Create a recursive function to compute the nth Fibonacci number.
- Write a function to count the occurrences of a character in a string.
- Implement a function to return the sum of all elements in a list.
- Write a function to check if a string is a palindrome.
- Implement a function to find the LCM of two numbers.
- Write a function to check if a number is an Armstrong number.
- Implement a lambda function to find the square of a number.
Lists
- Write a program to find the maximum and minimum elements in a list.
- Remove duplicate elements from a list.
- Find the sum of all elements in a list.
- Sort a list without using built-in functions.
- Reverse a list using slicing.
- Merge two sorted lists into a single sorted list.
- Write a program to rotate a list n times.
- Find the second largest element in a list.
- Implement a program to count the frequency of elements in a list.
- Remove all occurrences of a given element from a list.
Sets
- Write a program to find the union and intersection of two sets.
- Remove duplicates from a list using sets.
- Check if one set is a subset of another.
- Find the difference between two sets.
- Create a set from a string and print unique characters.
- Find common elements between three sets.
- Convert a list into a set and vice versa.
- Remove a specific element from a set.
- Write a program to check if two sets have any common elements.
- Find the symmetric difference between two sets.
Strings
- Reverse a string without using built-in functions.
- Count the number of vowels and consonants in a string.
- Check if a string is a palindrome.
- Find the frequency of each character in a string.
- Convert a string to uppercase and lowercase.
- Write a program to check if two strings are anagrams.
- Remove duplicate characters from a string.
- Find the longest word in a sentence.
- Replace all spaces in a string with %20.
- Find all substrings of a given string.
Tuples
- Find the maximum and minimum elements in a tuple.
- Convert a list into a tuple and vice versa.
- Find the index of an element in a tuple.
- Merge two tuples into one.
- Write a program to count occurrences of an element in a tuple.
- Convert a tuple of strings into a single concatenated string.
- Check if an element exists in a tuple.
- Find the sum of all elements in a numeric tuple.
- Sort a tuple of numbers.
- Write a program to convert a tuple into a dictionary.
Dictionary
- Write a program to merge two dictionaries.
- Find the maximum and minimum values in a dictionary.
- Sort a dictionary by its values.
- Write a program to check if a key exists in a dictionary.
- Count the frequency of words in a sentence using a dictionary.
- Write a program to remove a key from a dictionary.
- Convert a dictionary into a list of tuples and vice versa.
- Find the sum of all values in a dictionary.
- Write a program to get the key with the highest value in a dictionary.
- Implement a phone book using a dictionary.
OOPs (Object-Oriented Programming)
- Write a class representing a student with attributes and methods.
- Implement a class for a bank account with deposit and withdrawal functionalities.
- Write a Python program to demonstrate method overloading.
- Implement a class hierarchy demonstrating inheritance.
- Write a program to demonstrate multiple inheritance.
- Implement an abstract class in Python.
- Write a program demonstrating method overriding.
- Implement a program to manage employee records using OOPS.
- Write a program to demonstrate operator overloading.
- Implement a singleton class in Python.
Exception Handling
- Write a program to handle divide-by-zero exceptions.
- Implement a program to catch multiple exceptions.
- Write a program that raises a ValueError if the input is not a number.
- Implement a custom exception class.
- Write a program to demonstrate try, except, finally blocks.
- Implement exception handling for file handling.
- Catch and handle an IndexError.
- Write a program to raise a KeyError.
- Implement exception handling for type errors.
- Demonstrate the use of the else block in exception handling.
Study Notes
- Attempt each program on your own before checking any reference solution.
- Write clean, well-commented code and test with edge cases.
- Practice both iterative and recursive approaches where possible.
- Follow restrictions in the question (e.g., no built-in functions) carefully.
- Revise OOP and Exception Handling thoroughly, as they are commonly tested.






0 Ravula Kartheek:
Post a Comment