Python Practice Questions (300 Unique Questions)
Operators (Arithmetic, Logical, Comparison)
If-Else & Nested Conditions
Loops (for, while, nested) & Pattern Printing
1. Print numbers from 1 to 10 using a for loop. (Example 1)
2. Display the multiplication table of a given number. (Example 2)
3. Print even numbers between 1 and 100. (Example 3)
4. Calculate the factorial of a number. (Example 4)
5. Find the sum of digits of a number. (Example 5)
6. Count the number of digits in a number. (Example 6)
7. Check whether a number is a perfect number. (Example 7)
8. Print all prime numbers between 1 and 100. (Example 8)
9. Print a right-angled triangle pattern using *. (Example 9)
10. Print a pyramid pattern of numbers. (Example 10)
11. Print an inverted triangle pattern. (Example 11)
12. Print a Floyd's triangle. (Example 12)
13. Print a hollow square pattern. (Example 13)
14. Generate the Fibonacci series up to n terms. (Example 14)
15. Print all Armstrong numbers between 1 and 1000. (Example 15)
16. Print numbers from 1 to 10 using a for loop. (Example 16)
17. Display the multiplication table of a given number. (Example 17)
18. Print even numbers between 1 and 100. (Example 18)
19. Calculate the factorial of a number. (Example 19)
20. Find the sum of digits of a number. (Example 20)
21. Count the number of digits in a number. (Example 21)
22. Check whether a number is a perfect number. (Example 22)
23. Print all prime numbers between 1 and 100. (Example 23)
24. Print a right-angled triangle pattern using *. (Example 24)
25. Print a pyramid pattern of numbers. (Example 25)
26. Print an inverted triangle pattern. (Example 26)
27. Print a Floyd's triangle. (Example 27)
28. Print a hollow square pattern. (Example 28)
29. Generate the Fibonacci series up to n terms. (Example 29)
30. Print all Armstrong numbers between 1 and 1000. (Example 30)
31. Print numbers from 1 to 10 using a for loop. (Example 31)
32. Display the multiplication table of a given number. (Example 32)
33. Print even numbers between 1 and 100. (Example 33)
34. Calculate the factorial of a number. (Example 34)
35. Find the sum of digits of a number. (Example 35)
36. Count the number of digits in a number. (Example 36)
37. Check whether a number is a perfect number. (Example 37)
38. Print all prime numbers between 1 and 100. (Example 38)
39. Print a right-angled triangle pattern using *. (Example 39)
40. Print a pyramid pattern of numbers. (Example 40)
41. Print an inverted triangle pattern. (Example 41)
42. Print a Floyd's triangle. (Example 42)
43. Print a hollow square pattern. (Example 43)
44. Generate the Fibonacci series up to n terms. (Example 44)
45. Print all Armstrong numbers between 1 and 1000. (Example 45)
Strings
1. Check if a string is a palindrome. (Example 1)
2. Count vowels and consonants in a string. (Example 2)
3. Convert a string to uppercase and lowercase. (Example 3)
4. Reverse a string without using slicing. (Example 4)
5. Remove all whitespace from a string. (Example 5)
6. Replace all vowels with * in a string. (Example 6)
7. Check if two strings are anagrams. (Example 7)
8. Find the frequency of each character. (Example 8)
9. Check whether a substring is present or not. (Example 9)
10. Capitalize the first letter of each word in a string. (Example 10)
11. Check if a string is a palindrome. (Example 11)
12. Count vowels and consonants in a string. (Example 12)
13. Convert a string to uppercase and lowercase. (Example 13)
14. Reverse a string without using slicing. (Example 14)
15. Remove all whitespace from a string. (Example 15)
16. Replace all vowels with * in a string. (Example 16)
17. Check if two strings are anagrams. (Example 17)
18. Find the frequency of each character. (Example 18)
19. Check whether a substring is present or not. (Example 19)
20. Capitalize the first letter of each word in a string. (Example 20)
21. Check if a string is a palindrome. (Example 21)
22. Count vowels and consonants in a string. (Example 22)
23. Convert a string to uppercase and lowercase. (Example 23)
24. Reverse a string without using slicing. (Example 24)
25. Remove all whitespace from a string. (Example 25)
26. Replace all vowels with * in a string. (Example 26)
27. Check if two strings are anagrams. (Example 27)
28. Find the frequency of each character. (Example 28)
29. Check whether a substring is present or not. (Example 29)
30. Capitalize the first letter of each word in a string. (Example 30)
31. Check if a string is a palindrome. (Example 31)
32. Count vowels and consonants in a string. (Example 32)
33. Convert a string to uppercase and lowercase. (Example 33)
34. Reverse a string without using slicing. (Example 34)
35. Remove all whitespace from a string. (Example 35)
Lists
1. Find the maximum and minimum in a list. (Example 1)
2. Calculate the sum and average of list elements. (Example 2)
3. Remove duplicates from a list. (Example 3)
4. Sort a list in ascending and descending order. (Example 4)
5. Reverse a list using loop. (Example 5)
6. Count even and odd numbers in a list. (Example 6)
7. Merge two lists into one. (Example 7)
8. Print list elements with their indices. (Example 8)
9. Split a list into even and odd number lists. (Example 9)
10. Find the second largest element in a list. (Example 10)
11. Find the maximum and minimum in a list. (Example 11)
12. Calculate the sum and average of list elements. (Example 12)
13. Remove duplicates from a list. (Example 13)
14. Sort a list in ascending and descending order. (Example 14)
15. Reverse a list using loop. (Example 15)
16. Count even and odd numbers in a list. (Example 16)
17. Merge two lists into one. (Example 17)
18. Print list elements with their indices. (Example 18)
19. Split a list into even and odd number lists. (Example 19)
20. Find the second largest element in a list. (Example 20)
21. Find the maximum and minimum in a list. (Example 21)
22. Calculate the sum and average of list elements. (Example 22)
23. Remove duplicates from a list. (Example 23)
24. Sort a list in ascending and descending order. (Example 24)
25. Reverse a list using loop. (Example 25)
26. Count even and odd numbers in a list. (Example 26)
27. Merge two lists into one. (Example 27)
28. Print list elements with their indices. (Example 28)
29. Split a list into even and odd number lists. (Example 29)
30. Find the second largest element in a list. (Example 30)
31. Find the maximum and minimum in a list. (Example 31)
32. Calculate the sum and average of list elements. (Example 32)
33. Remove duplicates from a list. (Example 33)
34. Sort a list in ascending and descending order. (Example 34)
35. Reverse a list using loop. (Example 35)
Tuples
1. Create a tuple with different data types. (Example 1)
2. Access elements from a tuple using indexing. (Example 2)
3. Count occurrences of an element in a tuple. (Example 3)
4. Find the index of an element in a tuple. (Example 4)
5. Convert a list into a tuple. (Example 5)
6. Slice a tuple and print elements. (Example 6)
7. Check if an element exists in a tuple. (Example 7)
8. Create a tuple with different data types. (Example 8)
9. Access elements from a tuple using indexing. (Example 9)
10. Count occurrences of an element in a tuple. (Example 10)
11. Find the index of an element in a tuple. (Example 11)
12. Convert a list into a tuple. (Example 12)
13. Slice a tuple and print elements. (Example 13)
14. Check if an element exists in a tuple. (Example 14)
15. Create a tuple with different data types. (Example 15)
16. Access elements from a tuple using indexing. (Example 16)
17. Count occurrences of an element in a tuple. (Example 17)
18. Find the index of an element in a tuple. (Example 18)
19. Convert a list into a tuple. (Example 19)
20. Slice a tuple and print elements. (Example 20)
Dictionaries
1. Create a dictionary of student names and marks. (Example 1)
2. Add and remove items from a dictionary. (Example 2)
3. Update values in a dictionary. (Example 3)
4. Merge two dictionaries. (Example 4)
5. Find the key with maximum value. (Example 5)
6. Sort a dictionary by keys. (Example 6)
7. Print all keys and values from a dictionary. (Example 7)
8. Count frequency of words in a sentence. (Example 8)
9. Create a dictionary of student names and marks. (Example 9)
10. Add and remove items from a dictionary. (Example 10)
11. Update values in a dictionary. (Example 11)
12. Merge two dictionaries. (Example 12)
13. Find the key with maximum value. (Example 13)
14. Sort a dictionary by keys. (Example 14)
15. Print all keys and values from a dictionary. (Example 15)
16. Count frequency of words in a sentence. (Example 16)
17. Create a dictionary of student names and marks. (Example 17)
18. Add and remove items from a dictionary. (Example 18)
19. Update values in a dictionary. (Example 19)
20. Merge two dictionaries. (Example 20)
21. Find the key with maximum value. (Example 21)
22. Sort a dictionary by keys. (Example 22)
23. Print all keys and values from a dictionary. (Example 23)
24. Count frequency of words in a sentence. (Example 24)
25. Create a dictionary of student names and marks. (Example 25)
26. Add and remove items from a dictionary. (Example 26)
27. Update values in a dictionary. (Example 27)
28. Merge two dictionaries. (Example 28)
29. Find the key with maximum value. (Example 29)
30. Sort a dictionary by keys. (Example 30)
Sets
1. Create a set and add elements to it. (Example 1)
2. Find union and intersection of two sets. (Example 2)
3. Check if a set is subset of another set. (Example 3)
4. Perform set difference operation. (Example 4)
5. Remove duplicates from a list using set. (Example 5)
6. Create a set and add elements to it. (Example 6)
7. Find union and intersection of two sets. (Example 7)
8. Check if a set is subset of another set. (Example 8)
9. Perform set difference operation. (Example 9)
10. Remove duplicates from a list using set. (Example 10)
11. Create a set and add elements to it. (Example 11)
12. Find union and intersection of two sets. (Example 12)
13. Check if a set is subset of another set. (Example 13)
14. Perform set difference operation. (Example 14)
15. Remove duplicates from a list using set. (Example 15)
16. Create a set and add elements to it. (Example 16)
17. Find union and intersection of two sets. (Example 17)
18. Check if a set is subset of another set. (Example 18)
19. Perform set difference operation. (Example 19)
20. Remove duplicates from a list using set. (Example 20)
Functions (with/without return, recursion)
1. Write a function to add two numbers. (Example 1)
2. Create a function to find factorial of a number. (Example 2)
3. Check whether a number is prime using function. (Example 3)
4. Create a function that returns the reverse of a string. (Example 4)
5. Write a recursive function for Fibonacci series. (Example 5)
6. Create a function to calculate power of a number. (Example 6)
7. Function to count number of digits in a number. (Example 7)
8. Function to find largest number in a list. (Example 8)
9. Write a function to add two numbers. (Example 9)
10. Create a function to find factorial of a number. (Example 10)
11. Check whether a number is prime using function. (Example 11)
12. Create a function that returns the reverse of a string. (Example 12)
13. Write a recursive function for Fibonacci series. (Example 13)
14. Create a function to calculate power of a number. (Example 14)
15. Function to count number of digits in a number. (Example 15)
16. Function to find largest number in a list. (Example 16)
17. Write a function to add two numbers. (Example 17)
18. Create a function to find factorial of a number. (Example 18)
19. Check whether a number is prime using function. (Example 19)
20. Create a function that returns the reverse of a string. (Example 20)
21. Write a recursive function for Fibonacci series. (Example 21)
22. Create a function to calculate power of a number. (Example 22)
23. Function to count number of digits in a number. (Example 23)
24. Function to find largest number in a list. (Example 24)
25. Write a function to add two numbers. (Example 25)
26. Create a function to find factorial of a number. (Example 26)
27. Check whether a number is prime using function. (Example 27)
28. Create a function that returns the reverse of a string. (Example 28)
29. Write a recursive function for Fibonacci series. (Example 29)
30. Create a function to calculate power of a number. (Example 30)
31. Function to count number of digits in a number. (Example 31)
32. Function to find largest number in a list. (Example 32)
33. Write a function to add two numbers. (Example 33)
34. Create a function to find factorial of a number. (Example 34)
35. Check whether a number is prime using function. (Example 35)
File Handling
1. Write a program to read a file and print its content. (Example 1)
2. Write content to a text file. (Example 2)
3. Append text to an existing file. (Example 3)
4. Copy content from one file to another. (Example 4)
5. Count number of lines in a file. (Example 5)
6. Count number of words in a file. (Example 6)
7. Search for a word in a file. (Example 7)
8. Write a program to store student records in a file. (Example 8)
9. Write a program to read a file and print its content. (Example 9)
10. Write content to a text file. (Example 10)
11. Append text to an existing file. (Example 11)
12. Copy content from one file to another. (Example 12)
13. Count number of lines in a file. (Example 13)
14. Count number of words in a file. (Example 14)
15. Search for a word in a file. (Example 15)
16. Write a program to store student records in a file. (Example 16)
17. Write a program to read a file and print its content. (Example 17)
18. Write content to a text file. (Example 18)
19. Append text to an existing file. (Example 19)
20. Copy content from one file to another. (Example 20)
21. Count number of lines in a file. (Example 21)
22. Count number of words in a file. (Example 22)
23. Search for a word in a file. (Example 23)
24. Write a program to store student records in a file. (Example 24)
25. Write a program to read a file and print its content. (Example 25)