Python Tutorial Questions
Section A: Basic Python Programming
1. What is Python? Mention four advantages of Python programming.
2. Write a Python program to display:
Hello World
3. Create variables:
name = "John"
age = 20
height = 1.75
Display all variables.
4. Write a Python program to add, subtract, multiply, and divide two numbers.
5. Write a program to calculate:
y=3x2+2x+1 for x=5.
6. Explain the difference between: = and ==
7. Write a Python program to determine whether a number is even or odd.
8. Write a Python program that asks the user to enter two numbers and displays the largest
number.
9. Write a Python program to calculate the factorial of a number using a loop.
10. Write a Python program to display numbers from 1 to 20 using:
a for loop,
a while loop.
Section B: Lists and Array Slicing
11. Create the following list:
numbers = [10, 20, 30, 40, 50, 60]
12. Display:
the first element,
the last element,
the third element.
13. Using slicing, extract:
1
the first three elements,
the last three elements,
elements from index 1 to 4.
14. Reverse the following list using slicing:
numbers = [1, 2, 3, 4, 5]
15. Write a Python program to find:
the maximum value,
the minimum value,
the sum of elements in a list.
16. Write a Python program to append a new value to a list.
17. Write a Python program to remove an element from a list.
18. Write a Python program to sort a list in ascending order.
19. Explain the difference between:
append()
and
extend()
20. Write a Python program to count the number of occurrences of a value in a list.
Section C: String Manipulation
21. Create the string:
text = "Python Programming"
22. Display:
the first character,
the last character,
characters from index 0 to 5.
23. Convert the following string to uppercase:
"computer science"
24. Convert the following string to lowercase:
"DATA ANALYSIS"
25. Write a Python program to count the number of characters in a string.
26. Write a Python program to check whether a string is a palindrome.
27. Replace the word "Python" with "Java" in:
"Python is easy"
2
28. Split the following sentence into words:
"Machine learning is interesting"
29. Join the following list into a single string:
["Data", "Science", "Lab"]
30. Write a Python program to count the number of vowels in a string.
Section D: NumPy
31. Import the NumPy library.
32. Create the NumPy array:
[1, 2, 3, 4, 5]
33. Create a 3x3 matrix of zeros using NumPy.
34. Create a 4x4 identity matrix.
35. Generate 20 equally spaced values between 0 and 10.
36. Write a Python program to perform:
array addition,
array subtraction,
array multiplication.
37. Compute the mean, median, and standard deviation of:
[12, 15, 18, 20, 25]
38. Reshape the following array into a 2x3 matrix:
[1, 2, 3, 4, 5, 6]
39. Explain the difference between Python lists and NumPy arrays.
40. Write a Python program to find the transpose of a matrix.
Section E: Matplotlib
41. Import Matplotlib and plot:
y=x2 for: 0≤x≤100
42. Add:
a title,
x-axis label,
y-axis label
to the graph.
3
43. Plot both:
y=sin(x) and y=cos(x)
on the same graph.
44. Change:
line color,
line style,
marker style
of a plot.
45. Create a bar chart showing student marks:
[12, 15, 18, 10, 14]
46. Create a histogram of 100 random numbers.
47. Explain the purpose of:
[Link]()
Section F: Pandas
48. Import the Pandas library.
49. Create the following DataFrame:
Name Age
John 20
Mary 22
Paul 19
50. Display:
the first rows,
the last rows,
column names.
51. Add a new column named "Score" to a DataFrame.
52. Read a CSV file using Pandas.
53. Save a DataFrame into a CSV file.
54. Filter students whose age is greater than 20.
55. Explain the difference between:
loc[] and iloc[]
56. Calculate:
mean,
maximum,
4
minimum
values of a numeric column.
Section G: File Handling
57. Write a Python program to create and write into a text file.
58. Write a Python program to read a text file.
59. Append new content to an existing file.
60. Count the number of lines in a text file.
61. Write a Python program to copy the contents of one file into another file.
62. Explain the difference between file modes:
"r", "w", "a"
Section H: Regular Expressions
63. Import the regular expression module in Python.
64. Write a Python program to search for the word:
"data"
inside a sentence.
65. Write a Python program to extract all numbers from:
"My marks are 12, 15 and 18"
66. Validate whether an email address is valid using regular expressions.
67. Replace all spaces in a sentence with underscores using regex.
68. Write a Python program to count the number of words in a sentence using regex.
69. Explain the purpose of:
[Link]()
[Link]()
[Link]()
70. Write a Python program to extract all phone numbers from a text document.