Coding)
Theory-Based Questions
1. What is Python?
o Answer: Python is a high-level, interpreted programming language
known for its simplicity and readability. It supports multiple
programming paradigms, including procedural, object-oriented, and
functional programming.
2. What are the key features of Python?
o Answer: Python features include simple syntax, dynamic typing, high-
level built-in data structures, portability, vast libraries, and an active
community.
3. What is PEP 8?
o Answer: PEP 8 is a style guide for Python code, providing conventions
for code layout, naming conventions, and programming practices to
ensure readability and consistency.
4. What is a Python interpreter?
o Answer: A Python interpreter executes Python code line by line. It
translates Python code into machine code that the computer can
understand.
5. What are the different data types in Python?
o Answer: Common data types include integers, floats, strings, lists,
tuples, dictionaries, and sets.
6. What is the difference between a list and a tuple?
o Answer: Lists are mutable (can be changed), while tuples are
immutable (cannot be changed).
7. What is a dictionary in Python?
o Answer: A dictionary is an unordered collection of key-value pairs,
where each key is unique.
8. What are Python’s built-in data structures?
o Answer: Python’s built-in data structures include lists, tuples,
dictionaries, sets, and strings.
, 9. What is a function in Python?
o Answer: A function is a block of reusable code that performs a
specific task. It can take input parameters and return a result.
10.What are lambda functions in Python?
o Answer: Lambda functions are small anonymous functions defined
using the lambda keyword. They can take any number of arguments
but only have one expression.
11.What is the difference between del and remove in Python?
o Answer: del removes an item by its index, while remove() removes
the first occurrence of a specific value.
12.What is the difference between deepcopy and copy?
o Answer: copy() creates a shallow copy of the object, while
deepcopy() creates a new object recursively, copying all nested
objects.
13.Explain the difference between Python 2 and Python 3.
o Answer: Python 3 introduced several changes, including print
function syntax, integer division behavior, and Unicode string
handling.
14.What are global and local variables?
o Answer: Global variables are defined outside functions and can be
accessed from anywhere in the code, while local variables are
defined within functions and only accessible inside that function.
15.What is the purpose of the pass keyword?
o Answer: pass is used as a placeholder where code is syntactically
required but you don't want to execute any code.
16.What are Python modules and packages?
o Answer: A module is a file containing Python code that can be
imported into other programs. A package is a collection of modules.
17.What is the use of the __init__ method in Python?
o Answer: The __init__ method is a special method used to initialize an
object's attributes when an instance of a class is created.
18.What is the purpose of the self parameter in Python classes?
o Answer: self refers to the instance of the class and is used to access
instance variables and methods.