Python (Question Bank)
Python (Question Bank)
1. What is the primary objective of the "Introduction to Python Fundamentals and Programming
Basics" course?
a) To learn advanced Python techniques
b) To understand the basic syntax and principles of programming using Python
c) To master machine learning algorithms
d) To explore data analysis tools in Python
Answer: b) To understand the basic syntax and principles of programming using Python
Explanation: The course primarily focuses on understanding the basic programming syntax, structure, and
concepts in Python, ideal for beginners who are new to programming.
2. What is the expected outcome of completing the "Introduction to Python Fundamentals and
Programming Basics" course?
a) You will be able to develop full-scale applications in Python.
b) You will have a basic understanding of Python programming and be able to write simple Python
programs.
c) You will become proficient in Python web development.
d) You will gain knowledge of artificial intelligence and machine learning in Python.
Answer: b) You will have a basic understanding of Python programming and be able to write simple Python
programs.
Explanation: The course is designed for beginners and aims to equip students with a foundational
understanding of Python. It doesn’t cover advanced topics like full-scale app development, AI, or machine
learning.
3. Which of the following is NOT a key topic covered in the "Introduction to Python Fundamentals"
course?
a) Variables and Data Types
b) Control Structures (if, else, loops)
c) Functions and Modules
d) Neural Networks in Python
Explanation: Neural Networks and advanced machine learning concepts are not part of the fundamentals
course. The course focuses on the basics such as variables, control structures, and functions.
Answer: b) Python
Explanation: The course is centred around learning Python programming, one of the most popular
languages for beginners due to its simple and readable syntax.
Explanation: The course is designed for beginners to understand basic Python syntax, write simple
programs, and understand programming principles.
6. What is one of the core concepts you will learn in the "Introduction to Python Fundamentals"
course?
a) Advanced Object-Oriented Programming
b) Machine Learning with Python
c) Basic syntax, variables, data types, and control structures
d) Using Python for web scraping
Explanation: The course introduces you to the core programming concepts such as variables, data types,
basic control structures (loops, if-else), and functions.
Answer: c) Understand basic Python programming concepts and solve simple problems
Explanation: The course aims to provide students with foundational Python programming skills, enabling
them to solve basic problems, but it does not cover advanced topics like machine learning or web
development.
8. Which of the following is the main benefit of learning Python for beginners?
a) Python is difficult to learn and used in complex applications
b) Python is widely used in business applications only
c) Python is beginner-friendly due to its simple and readable syntax
d) Python is suitable only for mathematical computations
Explanation: Python is known for its easy-to-understand syntax, making it ideal for beginners who are new
to programming.
Explanation: Before moving on to advanced topics, beginners need to familiarize themselves with the core
syntax and structure of the Python language.
10. Which of the following programming concepts will be introduced in the "Introduction to Python
Fundamentals" course?
a) Recursion
b) Object-Oriented Programming
c) Data Structures and Algorithms
d) Variables and Functions
Explanation: The course focuses on foundational programming concepts, including variables and functions,
which are essential for writing simple Python programs.
Explanation: Python is a high-level, interpreted programming language used for a variety of applications,
such as web development, data science, automation, and more.
Explanation: Python was created by Guido van Rossum and was first released in 1991.
Explanation: Python has versions 1.x, 2.x, and 3.x. There is currently no Python 4.x version.
Explanation: Python’s syntax is designed to be easy to read and write, which makes it very popular for both
beginners and professionals.
15. Which of the following is a limitation of Python?
a) Python is platform-independent
b) Python has a large standard library
c) Python is slower compared to some compiled languages like C
d) Python supports object-oriented programming
Explanation: Python is an interpreted language, which tends to make it slower compared to compiled
languages like C, though the difference can be mitigated with optimization techniques.
16. What is the difference between a scripting language and a programming language?
a) A scripting language is compiled, while a programming language is interpreted
b) A scripting language is used for automating tasks, while a programming language is used for building applications
c) Scripting languages cannot handle complex logic, whereas programming languages can
d) There is no difference; they are the same
Answer: b) A scripting language is used for automating tasks, while a programming language is used for
building applications
Explanation: Scripting languages are generally used for automating tasks and smaller programs, whereas
programming languages are used to build more complex applications.
17. Which of the following is a major difference between Python 2 and Python 3?
a) Python 3 has better performance than Python 2
b) Python 2 is more compatible with older systems
c) Python 3 has print as a function, while Python 2 uses it as a statement
d) Python 2 supports object-oriented programming, while Python 3 does not
Explanation: One of the key differences is that in Python 3, print is a function (i.e., print()), while in Python
2, print is a statement (i.e., print).
18. Which of the following is NOT a typical use case for Python?
a) Web development
b) Data analysis and machine learning
c) Mobile app development
d) Low-level hardware programming
Explanation: Python is not typically used for low-level hardware programming, as languages like C or
assembly are more suited for that.
Answer: b) A compiler translates the entire code at once, while an interpreter translates code line by line
Explanation: A compiler translates the entire program at once and generates a machine-level file, whereas
an interpreter translates and executes the program line by line.
Explanation: Run-time refers to the time period during which a program is running or executing.
22. Which of the following is true regarding Python’s comparison with Java?
a) Python is generally faster than Java
b) Python has a more readable and concise syntax than Java
c) Java is easier to learn than Python
d) Python requires a virtual machine to run, whereas Java does not
Answer: b) Python has a more readable and concise syntax than Java
Explanation: Python is known for its simplicity and readability, which makes it easier to learn and write
compared to Java.
Answer: b) Extensive, with growth in fields like data science, AI, machine learning, and web development
Explanation: Python continues to be in high demand due to its versatility, ease of use, and its applications
in growing fields such as AI, machine learning, and data science.
24. Which of the following is a valid reason to use Python for web development?
a) Python has a rich ecosystem of frameworks like Django and Flask
b) Python is not suited for web development
c) Python is primarily used for low-level programming
d) Python has no support for web development
Answer: a) Python has a rich ecosystem of frameworks like Django and Flask
Explanation: Python is a popular choice for web development due to its frameworks, such as Django and
Flask, which simplify the process of building web applications.
Explanation: The 'flavours' of Python refer to the different implementations of the Python language, such as
CPython (the standard implementation), Jython (Python on the JVM), and IronPython (Python on the .NET
framework).
Explanation: Memory management involves allocating and deallocating memory resources to ensure
efficient usage during program execution, preventing memory leaks and optimizing performance.
27. Which of the following is NOT a type of memory typically managed in memory
management systems?
a) Stack memory
b) Heap memory
c) CPU memory
d) Storage memory
Explanation: Storage memory refers to disk-based storage (e.g., hard drives or SSDs), whereas memory
management primarily deals with managing stack, heap, and other runtime memory areas.
28. In Python, what is the role of the Global Interpreter Lock (GIL)?
a) It prevents race conditions in multi-threaded programs
b) It allows multiple threads to execute simultaneously on multiple processors
c) It manages memory allocation across different domains
d) It handles garbage collection
Explanation: The GIL ensures that only one thread executes Python bytecode at a time, preventing race
conditions but also limiting multi-threading performance in certain scenarios.
29. Which of the following memory areas is primarily used for dynamic memory
allocation in Python?
a) Stack
b) Heap
c) Cache
d) Storage
Answer: b) Heap
Explanation: The heap is the area of memory used for dynamic memory allocation, where objects are
allocated and managed during program execution in Python.
Explanation: The Python Memory Manager is responsible for managing memory allocation and handling
garbage collection to optimize memory usage during program execution.
31. Which of the following is a key feature of Python’s reference counting mechanism
for memory management?
a) It prevents memory leaks by automatically freeing memory when no longer in use
b) It counts how many times an object is referenced and frees it when the reference count is zero
c) It determines the size of memory objects
d) It reduces the memory consumption by sharing objects across programs
Answer: b) It counts how many times an object is referenced and frees it when the reference count is zero
Explanation: Python uses reference counting to track how many references exist for an object. When the
count drops to zero, the memory is deallocated.
Explanation: Cyclical references occur when two or more objects reference each other. Reference counting
cannot handle these situations, which can lead to memory leaks unless properly managed by garbage
collection.
33. Which technique does Python use to manage memory for objects over time in an
efficient way?
a) LIFO (Last In, First Out)
b) Generational garbage collection
c) Static memory allocation
d) Memory mapping
34. What is the role of the Allocator Domain in Python memory management?
a) It controls the allocation of memory across various operating systems
b) It is responsible for managing memory between different processes
c) It allocates and deallocates memory within specific memory regions of a program
d) It schedules memory allocation across multiple threads
Answer: c) It allocates and deallocates memory within specific memory regions of a program
Explanation: The Allocator Domain handles memory allocation and deallocation for different regions
within a Python program, helping manage memory efficiently.
Explanation: Immutable data types such as tuples and strings help reduce space complexity because they
prevent unnecessary memory allocation and copying, thereby optimizing memory usage.
Explanation: Python's garbage collection mechanism can detect and collect objects involved in reference
cycles, which reference counting alone cannot handle.
Answer: c) C Python
Explanation: C Python, the default implementation of Python, is primarily responsible for memory
management in Python environments, including memory allocation, garbage collection, and handling
reference counts.
38. How can an object in Python be made eligible for garbage collection?
a) By decreasing its reference count to zero
b) By manually deleting it from the program
c) By using memory management functions
d) By increasing its reference count
Explanation: When an object’s reference count drops to zero (i.e., no references point to the object), it
becomes eligible for garbage collection.
39. What is the main issue caused by cyclical references in Python's memory
management?
a) Objects are not created properly
b) Objects cannot be accessed or used
c) The memory occupied by these objects cannot be freed by reference counting
d) The Python interpreter becomes slower
Answer: c) The memory occupied by these objects cannot be freed by reference counting
Explanation: Cyclical references can create situations where reference counting cannot properly reclaim
memory, potentially leading to memory leaks until garbage collection resolves them.
Explanation: Using built-in functions efficiently avoids the creation of redundant objects, reducing the
overall memory footprint and optimizing space complexity.
Explanation: The first step when installing Python on Windows is to download the Python installer from
the official Python website (https://www.python.org).
Explanation: Adding Python to the Environmental Variables allows you to run Python directly from the
command line or terminal and makes it accessible throughout the system.
43. How can you check the Python version installed on your Windows machine?
a) By running the command python --version in the terminal
b) By opening the Python IDE
c) By typing python_version() in the Python shell
d) By checking the settings in the control panel
Explanation: To check the Python version installed, you can use the python --version command in the
terminal or command prompt.
Explanation: pip is the package manager for Python, which allows you to install, upgrade, or remove
Python packages.
45. Which of the following is a primary purpose of an Integrated Development Environment (IDE)?
a) To run the Python interpreter
b) To make programming easier by providing features like code completion and debugging tools
c) To compile Python code
d) To install Python packages
Answer: b) To make programming easier by providing features like code completion and debugging tools
Explanation: IDEs help streamline the development process by providing essential tools like code
completion, debugging, and error checking.
Explanation: In IDLE, you can run a Python program by selecting "Run" from the menu and then choosing
"Run Module."
Answer: c) 123variable
Explanation: Identifiers in Python cannot begin with a digit. They must start with a letter or an underscore.
Explanation: Literals are fixed values that are directly written into the code, such as numbers, strings, and
boolean values.
Answer: b) while
Explanation: while is a reserved keyword in Python used for looping. It cannot be used as an identifier.
Explanation: Comments are used to explain code, making it easier for others (and yourself) to understand
and maintain.
51. Which of the following is not a rule for writing Python identifiers?
a) Identifiers can include letters, digits, and underscores
b) Identifiers must not start with a number
c) Identifiers can be a keyword
d) Identifiers are case-sensitive
Explanation: Identifiers cannot be a reserved keyword in Python, such as while, for, def, etc.
Explanation: Python uses indentation to define the structure of the code and group related statements
together into blocks.
Explanation: The input() function is used to take input from the user in Python.
Explanation: Constants are values that, once defined, do not change throughout the execution of the
program.
55. Which of the following IDEs can be used for Python development?
a) Visual Studio
b) Thony
c) PyCharm
d) All of the above
Explanation: All these IDEs (Visual Studio, Thony, PyCharm) can be used for Python development.
Explanation: In Python, # is used to start a comment, allowing you to write explanations or disable certain
parts of the code.
57. Which of the following is the correct way to execute a Python file in a command line or terminal?
a) python filename.py
b) run filename.py
c) execute filename.py
d) start filename.py
Explanation: To run a Python script in the terminal, you use the command python filename.py, where
filename.py is your Python file.
Explanation: Python separates statements using newline characters and indentation, not semicolons like
many other programming languages.
Explanation: Python ignores comments when executing the program, and comments are only for human
readability.
Answer: d) Decimal
Explanation: While Python has built-in types like int, float, and str, Decimal is not a standard built-in
type and is part of the decimal module.
62. Which data type is used to represent true or false values in Python?
a) int
b) bool
c) string
d) set
Answer: b) bool
Explanation: The bool data type is used to represent boolean values, which are either True or False.
Answer: a) 5.5
Explanation: Python automatically converts the integer 3 to a float when performing arithmetic with a float,
so the result is 5.5.
64. What type of data does the following statement return in Python? type(42)
a) <class 'float'>
b) <class 'int'>
c) <class 'str'>
d) <class 'NoneType'>
Explanation: type(42) returns the class type of 42, which is an integer (int).
Answer: b) **
Answer: a) True
Explanation: The comparison operator == checks if the left-hand side value is equal to the right-hand side
value. Since both are equal, the result is True.
Answer: a) &
Explanation: The & operator is used to perform bitwise AND between two integers.
68. What is the result of the following expression: True and False?
a) True
b) False
c) Error
d) None
Answer: b) False
Explanation: The and operator returns True only if both operands are True. Since one operand is False,
the result is False.
Answer: b) is
Explanation: The is operator checks if two variables refer to the same object in memory, not just if their
values are equal.
Explanation: The ternary operator is a shorthand way to assign a value based on a condition. The syntax is:
value_if_true if condition else value_if_false.
Answer: a) 3
Explanation: The int() function truncates the decimal part when converting a float to an integer, so the
result is 3.
72. Which of the following is the correct way to convert a string '10' to an integer in Python?
a) int('10')
b) str('10')
c) float('10')
d) bool('10')
Answer: a) int('10')
Explanation: The int() function is used to convert a string that represents an integer into an actual integer.
73. What will be the result of the following code? not False
a) True
b) False
c) Error
d) None
Answer: a) True
Explanation: The not operator negates the value. Since False is negated, it returns True.
Explanation: Parentheses () have the highest precedence in Python and are evaluated first in expressions.
Answer: a) 2
Explanation: The // operator performs integer (floor) division, which discards the fractional part. Thus, 7
// 3 equals 2.
Answer: b) Set
Explanation: A set is an unordered collection of unique elements. Duplicates are removed when converting
a list to a set.
77. Which of the following operators is used for membership testing in Python?
a) is
b) in
c) &
d) ==
Answer: b) in
Explanation: The in operator checks if a value exists within a collection (like a list, tuple, or string).
78. What are Control Flow Statements in Python?
a) Statements that define the data type of a variable
b) Statements that control the flow of execution in a program
c) Statements that define functions in Python
d) Statements that handle exceptions
Explanation: Control flow statements in Python allow you to specify the order in which statements are executed.
79. Which of the following is an example of a decision control statement in Python? a) For loop
b) While loop
c) If statement
d) Continue statement
Answer: c) If statement
Explanation: Decision control statements are used to make decisions in a program. The if statement is used to test a
condition and execute code accordingly.
Answer: d) and
Explanation: The and operator is used to combine multiple conditions, where all conditions must be true for the
overall expression to be true.
81. What does the break statement do in a loop? a) Continues the loop with the next iteration
b) Exits the loop immediately
c) Skips the current iteration
d) None of the above
Explanation: The break statement is used to terminate the current loop and exit it.
Answer: a) Skips the current iteration and moves to the next one
Explanation: The continue statement is used to skip the rest of the code in the current iteration and move to the next
iteration.
Explanation: The pass statement is a null operation that is used to fill in the body of a loop, function, or class where
code is required syntactically but not yet implemented.
Explanation: A nested loop is simply a loop inside another loop. Both for and while loops can be nested.
85. Which of the following methods is used to remove spaces from the beginning and end of a string?
a) strip()
b) trim()
c) remove()
d) clear()
Answer: a) strip()
Explanation: The strip() method removes any leading and trailing whitespace from the string.
Explanation: Strings in Python are immutable, meaning once they are created, they cannot be changed. You can
create new strings, but the original string cannot be modified.
Answer: d) in
Explanation: The in operator is used to check if a substring exists in a string. It returns True if the substring is found,
and False otherwise.
88. Which of the following will split a string into a list of words?
a) split()
b) join()
c) partition()
d) slice()
Answer: a) split()
Explanation: The split() method splits a string into a list, separating the string by spaces or other specified delimiters.
89. Which of the following string methods can be used to count the occurrences of a substring?
a) find()
b) index()
c) count()
d) len()
Answer: c) count()
Explanation: The count() method is used to count the number of occurrences of a substring in the string.
Explanation: The join() method is used to join the elements of an iterable (like a list) into a single string, separated by
the string that calls the method.
91. Which of the following methods is used to add an element at the end of a Python list?
a) insert()
b) append()
c) extend()
d) pop()
Answer: b) append()
Explanation: The append() method adds an element to the end of the list.
Explanation: List slicing is used to get a subset (a portion) of a list based on index ranges.
93. Which of the following methods removes and returns the last item from a list?
a) pop()
b) remove()
c) del
d) extend()
Answer: a) pop()
Explanation: The pop() method removes and returns the last element from the list.
Explanation: The method lst.reverse() reverses the list in place, and lst[::-1] creates a new reversed list.
Answer: b) extend()
Explanation: The extend() method is used to append elements of another list to the end of the list.
96. Which of the following is used to create a new list containing only even numbers from an existing list?
a) List Slicing
b) List Comprehension
c) List Joining
d) List Copying
Explanation: List comprehension allows for creating a new list based on a condition, such as selecting only even
numbers.
Answer: d) len()
Explanation: The len() function is used to find the number of elements in a list.
98. Which of the following methods can be used to remove an element by its value from a list?
a) pop()
b) del
c) remove()
d) discard()
Answer: c) remove()
Explanation: The remove() method is used to remove the first occurrence of a specific value from the list.
99. How would you access the last element of the list lst = [1, 2, 3]?
a) lst[0]
b) lst[3]
c) lst[-1]
d) lst[-3]
Answer: c) lst[-1]
Explanation: Negative indexing allows you to access elements from the end of the list, with -1 referring to the last
element.
Explanation: A tuple is an ordered collection of elements, meaning the elements have a defined order, and it is
immutable, meaning it cannot be changed once created.
101. Which method is used to find the number of occurrences of an element in a tuple?
A) count()
B) index()
C) append()
D) find()
Answer: A) count()
Explanation: The count() method returns the number of times a specified element appears in a tuple.
102. Which operator can you use to check whether an element exists in a tuple?
A) in
B) is
C) ==
D) not
Answer: A) in
Explanation: Tuples are immutable, so attempting to change an element of a tuple will result in a `TypeError`.
104. How can you iterate through all the elements of a tuple?
a) Using a `for` loop
b) Using a `while` loop
c) Using a `for` loop with the `range()` function
d) All of the above
Explanation: Tuples can be iterated through using any loop, including a `for` loop directly or with `range()` in case
you want to access the indices.
Explanation: Tuple comprehension is a technique to create tuples in a concise way, similar to list comprehension, but
instead of square brackets, parentheses `()` are used.
106. Which of the following is true about the difference between tuples and lists?
a) Tuples are mutable, and lists are immutable
b) Lists are mutable, and tuples are immutable
c) Both tuples and lists are immutable
d) Both tuples and lists are mutable
Explanation: Lists are mutable, meaning their elements can be changed after creation, while tuples are immutable
and cannot be modified.
Explanation: The `str()` function can convert a tuple to its string representation.
108. How can you create a tuple from two different lists?
a) Using the `zip()` function
b) Using the `join()` method
c) Using the `extend()` method
d) Using the `append()` method
Explanation: The `zip()` function pairs elements from two lists together, which can be converted into a tuple of tuples.
Explanation: The `index()` method returns the index of the first occurrence of a specified element in a tuple.
Explanation: You can reverse a tuple using slicing `[::-1]`, which creates a new tuple in reverse order.