Python Programming Questions for Practice
1. What is Python? List any two features of Python.
2.
What do you mean by indentation in Python?
3. List any four keywords in Python.
4. Mention two advantages of using Python over other programming languages.
5. How are errors handled during Python compilation and execution?
6.
Define variables. Give an example of variable assignment.
7. List any four data types in Python.
8. What is the difference between mutable and immutable data types?
9. Differentiate between int, float, and complex data types.
10. What is a string? Give three basic string operations with examples.
11. How can you check the type of a variable in Python?
12. What is a list in Python?
13. Differentiate between a list and a tuple.
14. What are dictionary keys and values?
15. Mention one advantage of a dictionary over a list.
16. How can elements be added and removed from a dictionary?
17. Define control structure.
18. Write syntax for if-else statement in Python.
19. What is the use of 'elif' keyword?
20. Differentiate between 'while' and 'for' loops.
21. What is a nested loop? Give an example.
22. Explain the use of break and continue statements with examples.
23. Discuss the importance of indentation in control structures.
24. Write a short note on nested decision-making in Python.
25. Differentiate between runtime error and syntax error.
26. Explain the importance of error handling in programming.
27. Write a Python program to read data from a file and count the number of words.
28. What is a library in Python?
29. Define NumPy.
30. What is a Pandas DataFrame?
31. What is the function of pd.read_csv()?
32. Write a program using Pandas to read a CSV file and display the top five rows.
33. What is Matplotlib?
34. Mention two types of charts available in Seaborn.
35. What is data cleaning?
36. Write the syntax to plot a line graph using Matplotlib.
37. Explain how missing data can be handled in Pandas.
38. Illustrate the difference between univariate and multivariate analysis.
39. Write Python code to create a bar chart.
40. Explain the use of labels and titles in data visualization.
41. Write a Python program using Seaborn to visualize sales trends for different
regions.
42. Analyze how data visualization supports business decision-making.
43. What are open-source licenses?
44. Define software ethics.
45. Mention any two examples of open-source software.
46. What do you mean by code plagiarism?
47. Why is licensing important in software distribution?
48. Explain the importance of ethical coding practices.
49. Differentiate between open-source and proprietary software.
50. How can developers ensure compliance with open-source licenses?
51. Discuss ethical issues faced by programmers in business applications.
52. Evaluate the impact of open-source culture on innovation and learning.
53. Interpret the output of:
x = 10
y=5
x, y = y, x
y=y+2
print(x, y)
54. Explain the output of:
for i in range(1,4):
for j in range(i):
print('*', end='')
print()
55. Predict the output:
numbers = [1, 2, 3, 4]
squares = [x**2 for x in numbers]
print(squares)
56. What will be the output of:
x = ['Python', 'Java', 'C++']
print(' - '.join(x))
57. Explain:
def func(a, b=3, c=5):
return a + b + c
print(func(2, 4))
58. Interpret the result:
a = [1, 2, 3]
b=a
a.append(4)
print(b)
59. Analyze the output:
def greet(name):
return 'Hello, ' + name
print(greet('Alice'))
60. Predict the result:
import numpy as np
arr = np.array([1, 2, 3, 4])
print(arr.mean())
61. Explain what this code does and state its output:
import pandas as pd
data = {'A':[1,2], 'B':[3,4]}
df = pd.DataFrame(data)
print(df.T)
62. Assume you are working with a file named sales_data.csv with the following
columns:
Order_ID
1001
1002
1003
Date
202401-05
202401-07
202401-10
Region
Product
Quantity
Unit_Price
Total_Sales
Discount
Profit
Category
East
Laptop
3
55000
165000
0.1
12000
Electronics
West
Chair
5
3000
15000
0.05
2000
Furniture
North
Tablet
2
25000
50000
0.15
5000
Electronics
df = pd.read_csv('sales_data.csv')
df.info()
Interpret what information this command provides about the dataset.
63. Examine this code:
df = pd.read_csv('employee_data.csv')
print(df.describe())
What statistical summary will this output show?
64. The following code is executed:
df.isnull().sum()
Explain what this command does and how it can help in data cleaning.
65. Given this code:
df['Age'].fillna(df['Age'].mean(), inplace=True)
Interpret how missing values are handled here.
66. Consider this snippet:
df.drop_duplicates(inplace=True)
What is the purpose of this operation, and when should it be used?
67. Observe the code:
import matplotlib.pyplot as plt
plt.hist(df['Salary'], bins=10)
plt.show()
Interpret what this visualization represents.
68. The following command is used:
sns.boxplot(x='Department', y='Salary', data=df)
Explain how this visualization helps in understanding salary distribution.
69. Review this code:
df['Gender'].value_counts().plot(kind='bar')
plt.title('Gender Distribution')
plt.show()
What information can be interpreted from this output?
70. Examine this code:
df.corr()
What does this function return, and how can it be useful in data analysis?
71. Consider:
sns.heatmap(df.corr(), annot=True, cmap='coolwarm')
What kind of insights does this visualization provide?
72. The code below is executed:
plt.scatter(df['Experience'], df['Salary'])
plt.xlabel('Experience')
plt.ylabel('Salary')
plt.show()
Interpret the relationship that can be observed from the scatter plot.
73. Examine this snippet:
df = pd.read_csv('data.csv')
df = df.dropna(subset=['Revenue'])
What effect will this have on the dataset?
74. Analyze this code:
df['Bonus'] = df['Salary'] * 0.10
What transformation is being applied to the dataset?
75. The following code is run:
df.groupby('Department')['Salary'].mean()
Interpret what this line of code returns.
76. The following code is run:
sns.barplot(x='Department', y='Performance_Score', data=df)
What kind of interpretation can be made from this visualization?
77. The following code throws an error:
df = pd.readcsv('data.csv')
Identify the error and correct the code.
78. Examine this snippet:
plt.plot(df['sales'])
plt.title = 'Monthly Sales'
plt.show()
Find and correct the mistake in the code.
79. The following code does not display the plot:
import matplotlib.pyplot as plt
sns.barplot(x='Region', y='Revenue', data=df)
What line is missing?
80. The following code results in a KeyError:
df['age'].mean()
What could be the reason and how can it be fixed?
81. The code below fails to show a heatmap:
sns.heatmap(df.corr, annot=True)
Identify the issue and correct it.
82. The following code shows an empty plot:
sns.scatterplot(x='Experience', y='Salary', data='df')
Find and correct the mistake.
83. Debug this code:
df.dropna('Revenue', inplace=True)
Why is this incorrect, and what is the correct syntax?
84. The following code gives a syntax error:
plt.xlabel('Age')
plt.ylabel('Salary')
plt.show()
plt.title('Age vs Salary')
What is the correct order for the commands?
85. The code fails to save the cleaned data properly:
df.to_csv('cleaned.csv')
What argument is missing to exclude the index column?
86. Explain how Python has become the preferred programming language in data
analytics and AI-driven industries. Discuss its advantages over other languages
with reference to real-world use cases like Netflix’s recommendation engine or
Google’s AI projects.
87. Discuss how Integrated Development Environments (IDEs) such as PyCharm,
Jupyter Notebook, and VS Code enhance coding productivity. Illustrate with
examples how syntax highlighting, auto-completion, and debugging tools help
developers in large-scale data science projects.
88. Explain the different data types and variable declarations in Python. Describe how
they can be used to manage and analyze data in business contexts — for example,
tracking inventory data or sales performance using numeric and string variables.
89. Compare and contrast lists, tuples, and dictionaries in Python. Using a case study
of an e-commerce company, demonstrate how these data structures can be used to
manage product catalogs, customer profiles, and transaction details efficiently.
90. Explain how control structures and looping mechanisms (for, while, nested loops)
are applied to automate repetitive calculations in financial models, such as
computing compound interest or generating monthly EMI schedules.
91. Discuss how conditional logic is used in Python for building decision-making
algorithms, such as credit risk classification or fraud detection systems. Provide
theoretical explanation along with pseudo-code examples.
92. Explain the importance of file handling and exception control in automating
business reporting systems. Illustrate how Python can read, write, and manage
CSV files while handling runtime errors during file access in a payroll or invoicing
system.
93. Discuss how NumPy supports numerical and matrix-based computations in
industries such as manufacturing or healthcare analytics. Demonstrate with
examples like sensor data normalization or medical image data manipulation.
94. Describe the role of the Pandas library in managing and cleaning large datasets.
Explain its importance using a case study from retail analytics where missing
values, duplicate entries, and outliers are handled before visualization.
95. Explain how Python’s visualization libraries — Matplotlib and Seaborn —
transform raw data into actionable insights. Support your answer with an example
of visualizing customer purchasing patterns for marketing strategy optimization.
96. Discuss the process of building dynamic dashboards using Matplotlib and Seaborn
visualizations in Python. Explain how visual analytics dashboards can help a
logistics company track fleet performance or delivery efficiency.
97. Explain how Python serves as a foundational tool for machine learning
applications in banking, healthcare, or marketing. Discuss the workflow from data
preprocessing to visualization, with emphasis on Pandas, NumPy, and
visualization tools.
98. Discuss the ethical responsibilities of programmers in handling user data. Explain
concepts like open-source licensing, privacy compliance, and transparency in AI
systems with examples from real-world companies.
99. Define open-source licensing and describe its importance for collaborative
development in industries. Discuss how licensing impacts commercial use,
distribution, and innovation, with examples from popular Python libraries.
100. Explain how Python can be used to clean and visualize data using Pandas,
Matplotlib, and Seaborn. Describe the steps involved in importing a CSV file,
removing missing values, and creating graphs to show patterns or trends. Use an
example such as analyzing student scores, sales data, or customer feedback to
illustrate your answer.