0% found this document useful (0 votes)
0 views

Python (Question Bank)

The document outlines the objectives, expected outcomes, and key concepts of the 'Introduction to Python Fundamentals and Programming Basics' course, emphasizing basic programming syntax and principles for beginners. It covers topics such as variables, control structures, and memory management, while clarifying misconceptions about advanced topics like machine learning. Additionally, it highlights Python's advantages, limitations, and its future scope in various fields, including web development and data science.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Python (Question Bank)

The document outlines the objectives, expected outcomes, and key concepts of the 'Introduction to Python Fundamentals and Programming Basics' course, emphasizing basic programming syntax and principles for beginners. It covers topics such as variables, control structures, and memory management, while clarifying misconceptions about advanced topics like machine learning. Additionally, it highlights Python's advantages, limitations, and its future scope in various fields, including web development and data science.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

PYTHON

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

Answer: 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.

4. What is the main programming language used in the course?


a) Java
b) Python
c) C++
d) Ruby

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.

5. Which of the following best describes the outcome of the course?


a) Ability to work with databases in Python
b) Ability to write and understand simple Python code
c) Ability to create complex web applications using Python
d) Ability to implement data science algorithms

Answer: b) Ability to write and understand simple Python code

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

Answer: c) Basic syntax, variables, data types, and control structures

Explanation: The course introduces you to the core programming concepts such as variables, data types,
basic control structures (loops, if-else), and functions.

7. After completing the course, you should be able to:


a) Develop a fully functional machine learning model in Python
b) Debug complex programs and optimize performance
c) Understand basic Python programming concepts and solve simple problems
d) Build sophisticated web applications in Python

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

Answer: c) Python is beginner-friendly due to its simple and readable syntax

Explanation: Python is known for its easy-to-understand syntax, making it ideal for beginners who are new
to programming.

9. The first step in learning programming using Python is:


a) Learning to install libraries
b) Understanding the basic syntax and structure of the language
c) Designing complex user interfaces
d) Working on machine learning projects

Answer: b) Understanding the basic syntax and structure of the language

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

Answer: d) Variables and Functions

Explanation: The course focuses on foundational programming concepts, including variables and functions,
which are essential for writing simple Python programs.

11. What is Python?


a) A programming language used for web development
b) A type of snake
c) A high-level, interpreted programming language
d) A hardware device for programming

Answer: c) A high-level, interpreted programming language

Explanation: Python is a high-level, interpreted programming language used for a variety of applications,
such as web development, data science, automation, and more.

12. Who is the creator of Python?


a) Dennis Ritchie
b) Guido van Rossum
c) James Gosling
d) Bjarne Stroustrup

Answer: b) Guido van Rossum

Explanation: Python was created by Guido van Rossum and was first released in 1991.

13. Which of the following is NOT a version of Python?


a) Python 1.x
b) Python 2.x
c) Python 3.x
d) Python 4.x

Answer: d) Python 4.x

Explanation: Python has versions 1.x, 2.x, and 3.x. There is currently no Python 4.x version.

14. Which feature makes Python a popular programming language?


a) High-performance execution
b) Simple and readable syntax
c) Low-level programming
d) Limited application scope

Answer: b) Simple and readable syntax

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

Answer: c) Python is slower compared to some compiled languages like C

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

Answer: c) Python 3 has print as a function, while Python 2 uses it as a statement

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

Answer: 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.

19. What is the Python Virtual Machine (PVM)?


a) A virtual environment for creating Python programs
b) A compiler for translating Python code
c) The interpreter that executes Python code
d) A tool for debugging Python code

Answer: c) The interpreter that executes Python code


Explanation: The Python Virtual Machine (PVM) is part of the Python interpreter and executes Python
bytecode after the code is compiled.

20. What is the primary difference between a compiler and an interpreter?


a) A compiler translates code line by line, while an interpreter translates the entire code at once
b) A compiler translates the entire code at once, while an interpreter translates code line by line
c) A compiler is slower than an interpreter
d) An interpreter requires a separate step for debugging

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.

21. What does 'run-time' refer to in programming?


a) The time spent compiling the program
b) The time taken to execute the program after compilation
c) The time spent writing code
d) The time spent in debugging code

Answer: b) The time taken to execute the program after compilation

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.

23. What is the future scope of Python in career opportunities?


a) Limited due to competition from other languages
b) Extensive, with growth in fields like data science, AI, machine learning, and web development
c) Python is becoming obsolete and has no career scope
d) Python is only useful for academic purposes

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.

25. What does the term 'Flavours of Python' refer to?


a) Different coding styles in Python
b) Different Python implementations like CPython, Jython, IronPython, etc.
c) Different versions of Python
d) Different Python libraries

Answer: b) Different Python implementations like CPython, Jython, IronPython, etc.

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).

26. What is the main purpose of memory management in a programming language?


a) To store data permanently
b) To manage CPU usage
c) To efficiently allocate and deallocate memory for program execution
d) To optimize code performance

Answer: c) To efficiently allocate and deallocate memory for program execution

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

Answer: 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

Answer: a) It prevents race conditions in multi-threaded programs

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.

30. What is the purpose of the Python Memory Manager?


a) To increase the CPU usage
b) To handle memory allocation and garbage collection
c) To prevent the execution of large programs
d) To limit the number of variables in a program

Answer: b) To handle memory allocation and garbage collection

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.

32. Which of the following is true about cyclical references in Python?


a) They do not affect memory management
b) They are automatically cleaned up by reference counting
c) They may cause memory leaks if not handled correctly
d) They improve memory efficiency

Answer: c) They may cause memory leaks if not handled correctly

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

Answer: b) Generational garbage collection


Explanation: Python uses generational garbage collection, where objects are categorized into generations
based on their lifespan. This approach helps efficiently manage memory by focusing garbage collection
efforts on younger objects, which are more likely to become unreachable.

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.

35. What is one common way to reduce space complexity in Python?


a) Use immutable data types
b) Increase the size of the heap
c) Avoid using references
d) Use circular references

Answer: a) Use immutable data types

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.

36. Which of the following is true about garbage collection in Python?


a) Garbage collection occurs only when the program is terminated
b) Garbage collection uses reference counting to detect unreachable objects
c) The Python garbage collector can handle reference cycles
d) Python does not have a garbage collection mechanism

Answer: c) The Python garbage collector can handle reference cycles

Explanation: Python's garbage collection mechanism can detect and collect objects involved in reference
cycles, which reference counting alone cannot handle.

37. Which Python implementation is primarily responsible for memory management in


most Python environments?
a) Jython
b) PyPy
c) C Python
d) IronPython

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

Answer: a) By decreasing its reference count to zero

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.

40. How can we reduce space complexity in Python?


a) Use more complex data structures
b) Use built-in functions to avoid object duplication
c) Minimize memory allocation by using external storage
d) Increase the number of variables in the program

Answer: b) Use built-in functions to avoid object duplication

Explanation: Using built-in functions efficiently avoids the creation of redundant objects, reducing the
overall memory footprint and optimizing space complexity.

41. What is the first step when installing Python on Windows?


a) Verifying Python version
b) Downloading Python from the official website
c) Installing an IDE
d) Writing a Python program

Answer: b) Downloading Python from the official website

Explanation: The first step when installing Python on Windows is to download the Python installer from
the official Python website (https://www.python.org).

42. Why is it important to add Python to the Environmental Variables?


a) To enable Python to run from the command line
b) To make Python available to the operating system
c) To update Python’s version
d) Both A and B

Answer: d) Both A and B

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

Answer: a) By running the command python --version in the terminal

Explanation: To check the Python version installed, you can use the python --version command in the
terminal or command prompt.

44. What is the purpose of the pip tool in Python?


a) To install Python on your machine
b) To manage Python’s libraries and packages
c) To write Python programs
d) To debug Python programs

Answer: b) To manage Python’s libraries and packages

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.

46. How can you execute a Python program in IDLE?


a) By clicking on "Run" and selecting "Run Module"
b) By typing python program.py in the terminal
c) By clicking on "File" and selecting "Open"
d) By typing the Python code directly into the terminal

Answer: a) By clicking on "Run" and selecting "Run Module"

Explanation: In IDLE, you can run a Python program by selecting "Run" from the menu and then choosing
"Run Module."

47. Which of the following is not a valid identifier in Python?


a) my_variable
b) _var123
c) 123variable
d) variable123

Answer: c) 123variable

Explanation: Identifiers in Python cannot begin with a digit. They must start with a letter or an underscore.

48. What are literals in Python?


a) Reserved keywords in the Python language
b) Variables that store values
c) Constants, variables, and values directly used in code
d) Types of data like strings and integers

Answer: c) Constants, variables, and values directly used in code

Explanation: Literals are fixed values that are directly written into the code, such as numbers, strings, and
boolean values.

49. Which of the following is a Python keyword?


a) func
b) while
c) variable
d) print

Answer: b) while

Explanation: while is a reserved keyword in Python used for looping. It cannot be used as an identifier.

50. What is the primary benefit of using comments in Python code?


a) To execute the code faster
b) To explain the purpose of the code and improve readability
c) To run the code without errors
d) To make the code more complex

Answer: b) To explain the purpose of the code and improve readability

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

Answer: c) Identifiers can be a keyword

Explanation: Identifiers cannot be a reserved keyword in Python, such as while, for, def, etc.

52. What does Python use to define code blocks?


a) Curly braces {}
b) Indentation (spaces or tabs)
c) Parentheses ()
d) Square brackets []

Answer: b) Indentation (spaces or tabs)

Explanation: Python uses indentation to define the structure of the code and group related statements
together into blocks.

53. What function is used to take user input in Python?


a) input()
b) get_input()
c) scan()
d) prompt()
Answer: a) input()

Explanation: The input() function is used to take input from the user in Python.

54. What are constants in Python?


a) Variables that change during program execution
b) Fixed values that do not change during program execution
c) Functions that can only return a value once
d) Keywords that perform operations

Answer: b) Fixed values that do not change during program execution

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

Answer: d) All of the above

Explanation: All these IDEs (Visual Studio, Thony, PyCharm) can be used for Python development.

56. What is the role of the # symbol in Python?


a) It is used to start a comment
b) It indicates the start of a function
c) It defines a variable
d) It ends a line of code

Answer: a) It is used to start a comment

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

Answer: a) python 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.

58. What is the default Python version on most systems in 2025?


a) Python 2.x
b) Python 3.x
c) Python 4.x
d) Python 1.x

Answer: b) Python 3.x


Explanation: As of 2025, Python 3.x is the default version, as Python 2.x has reached its end of life.

59. What does Python use to identify separate statements in a program?


a) Semicolons ;
b) Parentheses ()
c) Newline characters and indentation
d) Commas ,

Answer: c) Newline characters and indentation

Explanation: Python separates statements using newline characters and indentation, not semicolons like
many other programming languages.

60. Which of the following is true regarding Python comments?


a) Comments are executed as part of the program
b) Python ignores comments during execution
c) Comments are written using the // syntax
d) Python requires comments for every function

Answer: b) Python ignores comments during execution

Explanation: Python ignores comments when executing the program, and comments are only for human
readability.

61. Which of the following is not a built-in data type in Python?


a) Integer
b) Float
c) String
d) Decimal

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.

63. What is the result of the following operation in Python: 3 + 2.5?


a) 5.5
b) 5
c) 2.5
d) Error

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'>

Answer: b) <class 'int'>

Explanation: type(42) returns the class type of 42, which is an integer (int).

65. Which operator is used for exponentiation in Python?


a) ^
b) **
c) *
d) //

Answer: b) **

Explanation: In Python, the ** operator is used to calculate the exponentiation of numbers.

66. What will be the output of the following code? 5 == 5


a) True
b) False
c) Error
d) None

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.

67. Which operator is used to perform bitwise AND in Python?


a) &
b) |
c) ^
d) ~

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.

69. Which operator is used to check object identity in Python?


a) ==
b) is
c) &
d) in

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.

70. Which of the following is an example of a ternary operator in Python?


a) x = 5 if y > 10 else 0
b) x = (y > 10)
c) x = 5
d) x = 10 + y

Answer: a) x = 5 if y > 10 else 0

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.

71. What is the output of the following code: int(3.5)?


a) 3
b) 3.0
c) Error
d) 3.5

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.

74. Which operator has the highest precedence in Python?


a) +
b) *
c) ()
d) ==
Answer: c) ()

Explanation: Parentheses () have the highest precedence in Python and are evaluated first in expressions.

75. What is the output of the following expression: 7 // 3?


a) 2
b) 2.33
c) 3
d) 1

Answer: a) 2

Explanation: The // operator performs integer (floor) division, which discards the fractional part. Thus, 7
// 3 equals 2.

76. What type of data structure is returned by set([1, 2, 2, 3])?


a) List
b) Set
c) Tuple
d) Dictionary

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

Answer: b) Statements that control the flow of execution in a program

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.

80. Which operator is used to combine multiple conditions in Python?


a) &
b) or
c) &&
d) and

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

Answer: b) Exits the loop immediately

Explanation: The break statement is used to terminate the current loop and exit it.

82. What is the function of the continue statement in a loop?


a) Skips the current iteration and moves to the next one
b) Exits the loop immediately
c) Starts the loop from the beginning
d) None of the above

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.

83. Which of the following is true about the pass statement?


a) It exits a loop
b) It skips a loop iteration
c) It is used as a placeholder for code that needs to be written later
d) It starts the next iteration of the loop

Answer: c) It is used as a placeholder for code that needs to be written later

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.

84. Which of the following is true about a nested loop in Python?


a) It refers to a loop inside another loop
b) It will run infinitely
c) It can only be used with for loops
d) It requires special syntax to work

Answer: a) It refers to a loop inside another loop

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.

86. Which of the following is true about strings in Python?


a) Strings are mutable.
b) Strings are immutable.
c) Strings can be changed using indexing.
d) Strings cannot contain special characters.
Answer: b) Strings are immutable.

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.

87. Which method can be used to find if a substring exists in a string?


a) find()
b) index()
c) count()
d) in

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.

90. What does the join() method do in Python?


a) Joins two strings together.
b) Joins a string with a list of strings.
c) Joins a list with a tuple.
d) Joins two lists together.

Answer: b) Joins a string with a list of strings.

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.

92. What does list slicing do in Python?


a) It allows modifying a list
b) It allows accessing a subset of the list
c) It removes elements from the list
d) It reverses the list

Answer: b) It allows accessing a subset 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.

94. Which of the following will reverse the list in Python?


a) lst.reverse()
b) lst[::-1]
c) reverse(lst)
d) Both a and b

Answer: d) Both a and b

Explanation: The method lst.reverse() reverses the list in place, and lst[::-1] creates a new reversed list.

95. Which function is used to combine two lists in Python?


a) append()
b) extend()
c) insert()
d) join()

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

Answer: b) List Comprehension

Explanation: List comprehension allows for creating a new list based on a condition, such as selecting only even
numbers.

97. How can you find the number of elements in a list?


a) count()
b) length()
c) size()
d) len()

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.

100. What is a tuple in Python?


A) An ordered and immutable collection of items
B) An unordered collection of items
C) A mutable collection of items
D) A sequence of characters

Answer: A) An ordered and immutable collection of items

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: The in operator checks whether an element is present in a tuple or not.

103. What will happen if you try to update an element in a tuple?

a) The tuple will be updated successfully


b) A `TypeError` will be raised
c) The element will be replaced
d) It will remove the element from the tuple

Answer: b) A `TypeError` will be raised

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

Answer: 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.

105. What is tuple comprehension in Python?

a) A way to create tuples using a comprehension syntax


b) A way to modify tuples using a comprehension syntax
c) A method to iterate through tuples
d) A method to convert tuples to lists

Answer: a) A way to create tuples using a comprehension syntax

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

Answer: b) Lists are mutable, and tuples are immutable

Explanation: Lists are mutable, meaning their elements can be changed after creation, while tuples are immutable
and cannot be modified.

107. How can you convert a tuple to a string in Python?


a) Using `str()` function
b) Using `tuple()` function
c) Using `join()` method
d) Using `list()` function

Answer: a) Using `str()` function

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

Answer. A) Using the `zip()` function

Explanation: The `zip()` function pairs elements from two lists together, which can be converted into a tuple of tuples.

109. What does the `index()` method do in a tuple?

a) It finds the index of the first occurrence of an element


b) It returns a tuple of indexes of all elements
c) It counts the number of occurrences of an element
d) It returns the tuple itself

Answer: A) It finds the index of the first occurrence of an element

Explanation: The `index()` method returns the index of the first occurrence of a specified element in a tuple.

110. How can you reverse a tuple in Python?


a) Using `reverse()` method
b) Using slicing `[::-1]`
c) Using `reversed()` method
d) Using `flip()` method

Answer: B) Using slicing `[::-1]`

Explanation: You can reverse a tuple using slicing `[::-1]`, which creates a new tuple in reverse order.

You might also like