0% found this document useful (0 votes)
85 views56 pages

Python 2025 Mcqs

The document covers key concepts in Python programming, including problem-solving steps, debugging, documentation, flowcharting, structured programming, and programming methodologies. It also discusses Python's syntax, memory management, and various programming features. Additionally, it provides a series of questions and answers to reinforce understanding of these topics.

Uploaded by

baliyanarpit291
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views56 pages

Python 2025 Mcqs

The document covers key concepts in Python programming, including problem-solving steps, debugging, documentation, flowcharting, structured programming, and programming methodologies. It also discusses Python's syntax, memory management, and various programming features. Additionally, it provides a series of questions and answers to reinforce understanding of these topics.

Uploaded by

baliyanarpit291
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

Python Unit 1:

1. What is the first step in problem-solving?

o a) Designing the solution

o b) Problem definition

o c) Debugging

o d) Program execution
Answer: b) Problem definition

2. Which of the following is NOT a characteristic of a well-defined problem?

o a) Clear objectives

o b) Uncertain requirements

o c) Specific constraints

o d) Definite scope
Answer: b) Uncertain requirements

3. The process of creating a blueprint for solving a problem is called:

o a) Debugging

o b) Problem design

o c) Program design

o d) Documentation
Answer: c) Program design

4. In problem-solving, what is the term for breaking a problem down into smaller sub-
problems?

o a) Problem decomposition

o b) Problem abstraction

o c) Problem iteration

o d) Debugging
Answer: a) Problem decomposition

5. Which of the following is the most efficient method of problem-solving?


o a) Trial and error

o b) Algorithmic approach

o c) Guessing

o d) Random approach
Answer: b) Algorithmic approach

Debugging and Types of Errors in Programming

6. What is debugging?

o a) Writing code

o b) Designing algorithms

o c) Testing and fixing errors in the code

o d) Deleting files
Answer: c) Testing and fixing errors in the code

7. Which of the following is an example of a syntax error?

o a) Division by zero

o b) Misspelled keywords

o c) Incorrect algorithm

o d) Incorrect data output


Answer: b) Misspelled keywords

8. Which type of error occurs when the program runs but produces incorrect results?

o a) Logical error

o b) Syntax error

o c) Runtime error

o d) Semantic error
Answer: a) Logical error

9. What type of error will occur if you try to access a variable that has not been defined
in Python?
o a) Runtime error

o b) Syntax error

o c) NameError

o d) ValueError
Answer: c) NameError

10. A runtime error in programming is also known as:

• a) Compile-time error

• b) Execution error

• c) Logical error

• d) Syntax error
Answer: b) Execution error

Documentation

11. Why is documentation important in programming?

• a) It increases the size of the program

• b) It helps others and yourself understand the code

• c) It slows down the execution of the program

• d) It helps in obfuscating the code


Answer: b) It helps others and yourself understand the code

12. Which of the following is a key component of program documentation?

• a) Comments within the code

• b) Variable names

• c) Operators used in the code

• d) Data types used


Answer: a) Comments within the code

13. Which is NOT a benefit of proper documentation in a program?

• a) Easier maintenance
• b) Faster execution

• c) Improved collaboration

• d) Better understanding
Answer: b) Faster execution

14. What type of documentation is aimed at end-users of the software?

• a) Code comments

• b) User manuals

• c) Inline documentation

• d) Variable documentation
Answer: b) User manuals

15. Which of the following is true about inline comments in Python?

• a) They are written using //

• b) They are written using /*...*/

• c) They are written using #

• d) They are written using <!—...-->


Answer: c) They are written using #

Flowcharting, Decision Tables, and Algorithms

16. What does a rectangle represent in a flowchart?

• a) Decision

• b) Input/output

• c) Process

• d) Flow of control
Answer: c) Process

17. Which symbol represents a decision in a flowchart?

• a) Rectangle

• b) Diamond
• c) Oval

• d) Circle
Answer: b) Diamond

18. Which of the following is true about algorithms?

• a) They must have infinite steps

• b) They must terminate after a finite number of steps

• c) They must always output an integer

• d) They are only used in programming


Answer: b) They must terminate after a finite number of steps

19. What is a decision table?

• a) A graphical way of representing decisions

• b) A table that lists all possible decisions and their corresponding actions

• c) A method for writing complex logic

• d) A way to track user input


Answer: b) A table that lists all possible decisions and their corresponding actions

20. Which of the following is the correct order of flowchart elements?

• a) Process → Decision → Start/End

• b) Start → Process → Decision → End

• c) Start → Decision → Process → End

• d) Decision → Start → Process → End


Answer: b) Start → Process → Decision → End

Structured Programming Concepts

21. Which of the following is NOT a principle of structured programming?

• a) Sequence

• b) Selection

• c) Goto statement
• d) Iteration
Answer: c) Goto statement

22. In structured programming, which of the following statements is used for selection?

• a) for loop

• b) if-else statement

• c) while loop

• d) print statement
Answer: b) if-else statement

23. What is the purpose of structured programming?

• a) To reduce complexity

• b) To make use of GOTO statements

• c) To execute faster

• d) To use more memory


Answer: a) To reduce complexity

24. Which control structure is used for iteration?

• a) if statement

• b) while loop

• c) switch statement

• d) break statement
Answer: b) while loop

25. What type of programming is based on the concept of dividing a program into smaller,
manageable modules?

• a) Procedural programming

• b) Object-oriented programming

• c) Functional programming

• d) Structured programming
Answer: d) Structured programming
Programming Methodologies: Top-down and Bottom-up

26. In top-down programming, the development starts with:

• a) Coding all modules at once

• b) Designing the most complex module first

• c) Breaking down the main problem into smaller sub-problems

• d) Writing the functions first


Answer: c) Breaking down the main problem into smaller sub-problems

27. In bottom-up programming, the focus is on:

• a) Writing the main function first

• b) Solving small problems and integrating them into larger systems

• c) Ignoring small details

• d) Starting with the most abstract function


Answer: b) Solving small problems and integrating them into larger systems

28. Which of the following is an advantage of the top-down approach?

• a) Easier to test small modules independently

• b) Easier to design a complete system from the start

• c) Allows incremental development of modules

• d) Focuses on detailed implementation early


Answer: b) Easier to design a complete system from the start

29. The bottom-up approach is particularly useful in:

• a) Object-oriented programming

• b) Machine learning algorithms

• c) Functional programming

• d) GOTO-based programming
Answer: a) Object-oriented programming

30. In top-down design, sub-problems are typically handled by:

• a) External libraries
• b) Functions and procedures

• c) Classes

• d) Conditional statements
Answer: b) Functions and procedures

Overview of Python Programming: Structure and Elements

31. Which of the following is the correct extension for a Python file?

• a) .txt

• b) .py

• c) .java

• d) .pyp
Answer: b) .py

32. What is the first line of a Python program typically used for?

• a) Importing libraries

• b) Printing output

• c) Writing comments

• d) Declaring variables
Answer: c) Writing comments

33. Which of the following is the correct way to print "Hello, World!" in Python?

• a) echo "Hello, World!"

• b) printf("Hello, World!")

• c) print("Hello, World!")

• d) cout << "Hello, World!";


Answer: c) print("Hello, World!")

34. What type of structure does a typical Python program follow?

• a) Compiled structure

• b) Linear structure
• c) Object-oriented structure

• d) Modular structure
Answer: d) Modular structure

35. In Python, what is used to define a block of code?

• a) Parentheses

• b) Curly braces

• c) Indentation

• d) Square brackets
Answer: c) Indentation

Python Memory Management

36. How does Python handle memory management?

• a) Manually through pointers

• b) Through garbage collection

• c) By assigning memory to the stack only

• d) Memory is managed by the programmer


Answer: b) Through garbage collection

37. What is the name of the built-in Python memory manager?

• a) MemoryAllocator

• b) GarbageCollector

• c) pymalloc

• d) PyMem
Answer: c) pymalloc

38. What is the purpose of the del keyword in Python?

• a) To delete files

• b) To delete variables and free memory

• c) To delete functions
• d) To delete comments
Answer: b) To delete variables and free memory

39. When does Python's garbage collector typically run?

• a) After every line of code

• b) After a variable is created

• c) Automatically when memory is no longer used

• d) Manually by the programmer


Answer: c) Automatically when memory is no longer used

40. What is a memory leak in the context of Python programming?

• a) Running out of stack memory

• b) A program that uses an infinite loop

• c) Allocated memory that is never freed

• d) Memory that is initialized but never used


Answer: c) Allocated memory that is never freed

Miscellaneous

41. Which of the following is NOT a feature of Python?

• a) High-level language

• b) Compiled language

• c) Interpreted language

• d) Object-oriented
Answer: b) Compiled language

42. What is the main advantage of Python over low-level programming languages?

• a) Faster execution time

• b) Easier to write and maintain code

• c) Less memory usage


• d) Direct hardware access
Answer: b) Easier to write and maintain code

43. Which function is used to get the length of a list in Python?

• a) size()

• b) length()

• c) len()

• d) count()
Answer: c) len()

44. What will be the output of the following Python code: print(type(10))?

• a) <class 'int'>

• b) <class 'float'>

• c) Integer

• d) Number
Answer: a) <class 'int'>

45. What type of error is produced by the following Python code? print(10/0)

• a) SyntaxError

• b) ZeroDivisionError

• c) ValueError

• d) TypeError
Answer: b) ZeroDivisionError

46. Which of the following keywords is used to define a function in Python?

• a) define

• b) func

• c) def

• d) lambda
Answer: c) def

47. What will be the output of the following Python code: print(2**3)?
• a) 5

• b) 8

• c) 6

• d) 9
Answer: b) 8

48. Which keyword is used for exception handling in Python?

• a) catch

• b) exception

• c) try

• d) error
Answer: c) try

49. What is the purpose of the is keyword in Python?

• a) To compare values

• b) To compare memory locations

• c) To check type of variable

• d) To declare a variable
Answer: b) To compare memory locations

50. What is the correct syntax for importing a module in Python?

• a) import library_name

• b) module library_name

• c) include library_name

• d) from library_name
Answer: a) import library_name

Unit 2:

Introduction to Python: Python Interpreter, Python as a Calculator, Python Shell, Indentation

1. What is the main purpose of the Python interpreter?

o a) To compile the code


o b) To interpret and execute Python code

o c) To create Python applications

o d) To analyze Python libraries


Answer: b) To interpret and execute Python code

2. What is the Python Shell used for?

o a) Writing and saving Python scripts

o b) Executing Python commands interactively

o c) Compiling Python programs

o d) Debugging Python programs


Answer: b) Executing Python commands interactively

3. Which of the following is correct syntax to use Python as a calculator?

o a) print 2 + 3

o b) print(2 + 3)

o c) output(2 + 3)

o d) cout << 2 + 3
Answer: b) print(2 + 3)

4. How do you represent indentation in Python?

o a) Using braces { }

o b) Using parentheses ( )

o c) Using colons :

o d) Using spaces or tabs


Answer: d) Using spaces or tabs

5. In Python, which of the following is a valid arithmetic operation?

o a) 5 * 2

o b) 5 # 2

o c) 5 **
o d) 5 @ 2
Answer: a) 5 * 2

Atoms, Identifiers, Keywords, Literals, Strings, Operators

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

o a) 2nd_variable

o b) firstVariable

o c) @variable

o d) None
Answer: b) firstVariable

7. Which of the following is NOT a keyword in Python?

o a) if

o b) elif

o c) true

o d) return
Answer: c) true (correct form is True)

8. What is a literal in Python?

o a) A type of function

o b) A fixed value like a number or string

o c) A variable name

o d) An operator
Answer: b) A fixed value like a number or string

9. Which of the following is a valid string in Python?

o a) 'Hello'

o b) Hello

o c) 123Hello
o d) "123
Answer: a) 'Hello'

10. Which operator is used for exponentiation in Python?

o a) *

o b) **

o c) ^

o d) ~
Answer: b) **

11. Which operator is used to compare two values in Python?

o a) ==

o b) =

o c) &

o d) !
Answer: a) ==

12. Which of the following is a bitwise operator in Python?

o a) |

o b) and

o c) or

o d) &&
Answer: a) |

13. Which operator is used for logical AND in Python?

o a) &&

o b) &

o c) and

o d) |
Answer: c) and

14. What is the output of 3 > 2 and 2 > 1 in Python?


o a) False

o b) True

o c) 0

o d) None
Answer: b) True

15. What does the following Python expression return: 5 > 3 if True else 3 > 5?

o a) True

o b) False

o c) SyntaxError

o d) None
Answer: a) True

16. Which operator is used to assign a value to a variable in Python?

o a) ==

o b) =

o c) ->

o d) :=
Answer: b) =

17. Which of the following is NOT a valid operator in Python?

o a) +=

o b) ++

o c) -=

o d) **
Answer: b) ++

18. Which operator is used for the bitwise XOR operation?

o a) |

o b) ^

o c) ~
o d) &
Answer: b) ^

19. Which operator is NOT supported in Python?

o a) ++

o b) //

o c) **

o d) %
Answer: a) ++

20. What does the += operator do in Python?

o a) Adds two values and assigns them to a variable

o b) Multiplies two values

o c) Subtracts two values

o d) Divides two values


Answer: a) Adds two values and assigns them to a variable

Creating Python Programs: Input and Output Statements, Control Statements, Defining
Functions, Errors and Exceptions

21. Which of the following functions is used to take input from the user in Python?

o a) input()

o b) raw_input()

o c) get_input()

o d) read()
Answer: a) input()

22. What will be the output of the following code: print("Hello", "World")?

o a) Hello,World

o b) Hello World

o c) HelloWorld
o d) Hello-World
Answer: b) Hello World

23. Which of the following control structures is used for looping in Python?

o a) if

o b) for

o c) else

o d) elif
Answer: b) for

24. What is the purpose of the break statement in Python?

o a) To terminate a loop prematurely

o b) To exit the program

o c) To continue the loop

o d) To skip the rest of the loop


Answer: a) To terminate a loop prematurely

25. What is the purpose of the continue statement in Python?

o a) To exit the program

o b) To skip the current iteration of the loop and continue with the next

o c) To stop the loop

o d) To restart the program


Answer: b) To skip the current iteration of the loop and continue with the next

26. What is the output of the following code: print(1 == 1 and 2 == 2)?

o a) True

o b) False

o c) None

o d) 0
Answer: a) True

27. What is the output of the following code: print(10 / 3)?


o a) 3

o b) 3.33

o c) 3.3333333333333335

o d) None
Answer: c) 3.3333333333333335

28. Which of the following functions can be used to exit a Python program?

o a) sys.exit()

o b) exit()

o c) quit()

o d) All of the above


Answer: d) All of the above

29. What is the difference between the break and continue statements in Python?

o a) break terminates the loop, while continue skips the current iteration

o b) continue terminates the loop, while break skips the current iteration

o c) Both statements exit the loop

o d) Both statements continue to the next iteration


Answer: a) break terminates the loop, while continue skips the current iteration

30. What will happen if an exception is not handled in Python?

o a) The program continues execution

o b) The program terminates abruptly

o c) The exception is ignored

o d) The program skips the exception block


Answer: b) The program terminates abruptly

Iteration and Recursion: Conditional Execution, Nested Conditionals, Return Statement

31. What is recursion in Python?

o a) A function that calls itself


o b) A loop inside a function

o c) A conditional statement inside a function

o d) An infinite loop
Answer: a) A function that calls itself

32. What is the output of the following code: print(5 if 4 > 2 else 10)?

o a) 5

o b) 10

o c) None

o d) SyntaxError
Answer: a) 5

33. Which statement is used to return a value from a function in Python?

o a) break

o b) return

o c) exit

o d) continue
Answer: b) return

34. Which of the following is an example of a loop in Python?

o a) for

o b) if

o c) elif

o d) else
Answer: a) for

35. What is the output of the following Python code: for i in range(3): print(i)?

o a) 0 1 2

o b) 1 2 3

o c) 1 2 3 4
o d) None
Answer: a) 0 1 2

36. Which of the following is true about nested conditionals?

o a) Conditional statements inside other conditional statements

o b) Functions inside loops

o c) Loops inside functions

o d) Recursive functions
Answer: a) Conditional statements inside other conditional statements

37. Which of the following is the correct syntax for a recursive function?

o a) def func(): return func()

o b) def func(): return 0

o c) def func(): print("Hello")

o d) def func(): pass


Answer: a) def func(): return func()

38. What is the base condition in recursion?

o a) A condition to terminate recursion

o b) A condition to start the loop

o c) A condition to continue recursion indefinitely

o d) None of the above


Answer: a) A condition to terminate recursion

39. Which of the following is an example of iteration in Python?

o a) Recursion

o b) Looping through a list

o c) Calling a function

o d) Importing a module
Answer: b) Looping through a list

40. What is the output of the following Python code: while True: break print('Hello')?
o a) Hello

o b) True

o c) None

o d) No output
Answer: d) No output

41. Which of the following is a recursive data structure?

o a) Stack

o b) Queue

o c) Tree

o d) List
Answer: c) Tree

42. What is the output of the following Python code: if 4 > 5: print('A') elif 4 < 5: print('B')
else: print('C')?

o a) A

o b) B

o c) C

o d) None
Answer: b) B

43. Which of the following is an alternative execution in Python?

o a) if

o b) elif

o c) else

o d) all of the above


Answer: d) all of the above

44. Which of the following is an example of conditional execution in Python?

o a) if

o b) for
o c) else

o d) while
Answer: a) if

45. What is the output of the following Python code: def f(): return 1 print(f())?

o a) None

o b) 1

o c) True

o d) False
Answer: b) 1

46. Which of the following is an example of a nested conditional?

o a) if x > 0: if y > 0: print(x, y)

o b) if x > 0: print(x)

o c) else: print(x)

o d) elif x > 0: print(x)


Answer: a) if x > 0: if y > 0: print(x, y)

47. Which of the following will stop the recursion in a recursive function?

o a) Base condition

o b) Loop

o c) return statement

o d) break statement
Answer: a) Base condition

48. Which statement is used to terminate the execution of a function?

o a) return

o b) break

o c) exit

o d) continue
Answer: a) return
49. What is the output of the following Python code: x = [1, 2, 3] for i in x: print(i)?

o a) 1 2 3

o b) 1

o c) None

o d) 0
Answer: a) 1 2 3

50. Which statement is used to check for a condition in a loop?

o a) if

o b) elif

o c) else

o d) while
Answer: d) while

Unit 3:

Recursion, Stack Diagrams for Recursive Functions

1. What is recursion in Python?

o a) A function that calls itself

o b) A loop inside a function

o c) A condition that terminates a program

o d) A function that calls other functions


Answer: a) A function that calls itself

2. Which of the following is true about recursion?

o a) Every recursive function must have a base case

o b) Recursive functions cannot call other functions

o c) Recursion is always faster than iteration

o d) Recursion uses less memory than loops


Answer: a) Every recursive function must have a base case

3. In recursion, the function calls are stored in a stack. What does the stack store?
o a) Function names

o b) Parameters and return values

o c) Variables only

o d) Loops
Answer: b) Parameters and return values

4. What is a stack overflow in recursion?

o a) When too many functions are called without a base case

o b) When there is no recursive function

o c) When a stack is filled with too much data

o d) When a program terminates unexpectedly


Answer: a) When too many functions are called without a base case

5. What is the base case in a recursive function?

o a) A case that stops recursion

o b) The first function call

o c) The last function call

o d) The case when recursion begins again


Answer: a) A case that stops recursion

6. Which data structure is used internally by the system to store recursive function calls?

o a) Queue

o b) Stack

o c) List

o d) Dictionary
Answer: b) Stack

7. In a stack diagram for a recursive function, what does each frame represent?

o a) A function call with its parameters and return value

o b) A loop inside the function

o c) The number of times a function is called


o d) The end of recursion
Answer: a) A function call with its parameters and return value

8. Which of the following scenarios is a good use of recursion?

o a) Sorting an array

o b) Calculating the factorial of a number

o c) Traversing a list

o d) Running an infinite loop


Answer: b) Calculating the factorial of a number

9. What happens when a recursive function lacks a base case?

o a) It results in infinite recursion

o b) It runs without any issues

o c) It terminates after one call

o d) It produces an immediate error


Answer: a) It results in infinite recursion

10. What is the correct base case for a recursive function calculating the factorial of a
number n?

o a) if n == 0: return 1

o b) if n == 1: return 1

o c) if n == 2: return 2

o d) if n == 10: return 10
Answer: a) if n == 0: return 1

Multiple Assignment

11. Which of the following is an example of multiple assignment in Python?

o a) x = 1, 2, 3

o b) a, b, c = 1, 2, 3

o c) a = b = c = 3
o d) Both b and c
Answer: d) Both b and c

12. What will the following code output: a, b = 5, 10; print(a, b)?

o a) 5 10

o b) 10 5

o c) 15

o d) SyntaxError
Answer: a) 5 10

13. What is the result of x, y = y, x in Python?

o a) It swaps the values of x and y

o b) It assigns y to x

o c) It assigns x to y

o d) It raises a SyntaxError
Answer: a) It swaps the values of x and y

14. Which of the following is NOT valid multiple assignment in Python?

o a) a, b = 1, 2

o b) x = y = z = 0

o c) p, q = (1, 2)

o d) m, n, o = 4, 5
Answer: d) m, n, o = 4, 5 (requires 3 values)

15. What does x, y, z = 1, 2, 3 represent?

o a) Tuple unpacking

o b) Multiple assignment

o c) List assignment

o d) Both a and b
Answer: d) Both a and b
The while Statement

16. What is the syntax for a while loop in Python?

o a) while(condition):

o b) for(condition):

o c) loop(condition):

o d) if(condition):
Answer: a) while(condition):

17. What will the following code output: x = 0; while x < 3: print(x); x += 1?

o a) 0 1 2

o b) 1 2 3

o c) 3 2 1

o d) None
Answer: a) 0 1 2

18. Which of the following is used to stop a while loop prematurely?

o a) break

o b) continue

o c) exit

o d) return
Answer: a) break

19. What will happen if the condition in a while loop never becomes False?

o a) The loop will execute infinitely

o b) The loop will terminate automatically

o c) The program will terminate

o d) The loop will skip all iterations


Answer: a) The loop will execute infinitely

20. What is the difference between break and continue in a while loop?

o a) break exits the loop, continue skips the current iteration


o b) continue exits the loop, break skips the current iteration

o c) Both stop the loop

o d) Both skip the current iteration


Answer: a) break exits the loop, continue skips the current iteration

Tables and Two-Dimensional Tables

21. What is a two-dimensional table in Python?

o a) A list of lists

o b) A dictionary of lists

o c) A set of tuples

o d) A tuple of dictionaries
Answer: a) A list of lists

22. How can you access the element at the second row and third column in a 2D list table?

o a) table[2][3]

o b) table[1][2]

o c) table[2, 3]

o d) table(1, 2)
Answer: b) table[1][2]

23. Which method can be used to create an empty 2D table with 3 rows and 4 columns in
Python?

o a) [[0]*4]*3

o b) [[0]*3]*4

o c) [[0 for _ in range(4)] for _ in range(3)]

o d) [[4]*3]
Answer: c) [[0 for _ in range(4)] for _ in range(3)]

24. Which of the following operations is invalid for a 2D list?

o a) Accessing an element using two indices


o b) Appending a new row

o c) Deleting a column

o d) Printing the entire table


Answer: c) Deleting a column (Python does not have built-in column removal for
lists)

25. What is the output of table = [[1, 2], [3, 4]]; print(table[1][1])?

o a) 1

o b) 3

o c) 4

o d) 2
Answer: c) 4

Strings and Lists

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

o a) Strings are mutable

o b) Strings are immutable

o c) Strings are a compound data type

o d) Strings are iterable


Answer: b) Strings are immutable

27. What is the output of the following code: print(len('Hello'))?

o a) 4

o b) 5

o c) 6

o d) SyntaxError
Answer: b) 5

28. Which of the following can be used to traverse a string in Python?

o a) for loop
o b) while loop

o c) Both a and b

o d) None of the above


Answer: c) Both a and b

29. What will be the output of s = "Hello"; print(s[1:4])?

o a) ell

o b) Hel

o c) lo

o d) llo
Answer: a) ell

30. How do you compare two strings in Python?

o a) Using ==

o b) Using !=

o c) Using is

o d) Both a and b
Answer: d) Both a and b

String Slices, String Comparison, Find Function

31. What does s = "abcdef"; print(s[::2]) output?

o a) ace

o b) bdf

o c) abc

o d) None
Answer: a) ace

32. What will be the output of s = "python"; print(s.find('y'))?

o a) 1

o b) 2
o c) -1

o d) 0
Answer: a) 1

33. Which function is used to check if one string contains another string?

o a) in

o b) contains

o c) find

o d) search
Answer: a) in

34. What does the find function return if the substring is not found in the string?

o a) -1

o b) 0

o c) None

o d) False
Answer: a) -1

35. What will be the output of s = "hello world"; print(s.find("world"))?

o a) 6

o b) 5

o c) 0

o d) 1
Answer: a) 6

More on Strings and Lists

36. Which function can convert a string into a list of characters?

o a) list()

o b) split()

o c) join()
o d) None
Answer: a) list()

37. What will be the result of print("hello".upper())?

o a) HELLO

o b) hello

o c) Hello

o d) Error
Answer: a) HELLO

38. What will be the output of print("abc" < "xyz")?

o a) True

o b) False

o c) None

o d) Error
Answer: a) True

39. What is the result of s = "python"; print(s[1:4])?

o a) yth

o b) pyt

o c) tho

o d) Error
Answer: a) yth

40. Which method removes leading and trailing whitespaces from a string?

o a) strip()

o b) remove()

o c) replace()

o d) delete()
Answer: a) strip()
Additional Topics on Lists and Strings

41. How do you concatenate two lists in Python?

o a) list1 + list2

o b) list1.append(list2)

o c) list1.join(list2)

o d) concatenate(list1, list2)
Answer: a) list1 + list2

42. Which of the following creates a list in Python?

o a) list()

o b) []

o c) Both a and b

o d) None of the above


Answer: c) Both a and b

43. What will be the output of list("hello")?

o a) ['h', 'e', 'l', 'l', 'o']

o b) ['hello']

o c) ['h', 'hello']

o d) Error
Answer: a) ['h', 'e', 'l', 'l', 'o']

44. Which method adds an element to the end of a list?

o a) append()

o b) add()

o c) extend()

o d) insert()
Answer: a) append()

45. What will be the result of print([1, 2] + [3, 4])?

o a) [1, 2, 3, 4]
o b) [1, 2]

o c) [3, 4]

o d) None
Answer: a) [1, 2, 3, 4]

46. Which of the following is not a valid list operation?

o a) list.append()

o b) list.pop()

o c) list.insert()

o d) list.trim()
Answer: d) list.trim()

47. What will be the result of s = "123"; list(s)?

o a) ['1', '2', '3']

o b) [1, 2, 3]

o c) ["123"]

o d) Error
Answer: a) ['1', '2', '3']

48. Which method converts a list into a string?

o a) join()

o b) str()

o c) split()

o d) format()
Answer: a) join()

49. Which method returns the index of the first occurrence of a value in a list?

o a) find()

o b) index()

o c) locate()
o d) search()
Answer: b) index()

50. How can you remove an element from a list by its index in Python?

o a) del list[index]

o b) list.remove(index)

o c) list.pop(index)

o d) Both a and c
Answer: d) Both a and c

Unit 4:

Looping and Counting, List Values, Accessing Elements

1. Which Python statement is used to loop over a sequence of items?

o a) while

o b) for

o c) loop

o d) repeat Answer: b) for

2. What does the following code do? for i in range(5): print(i)

o a) Prints numbers from 0 to 4

o b) Prints numbers from 1 to 5

o c) Prints 5

o d) Prints nothing Answer: a) Prints numbers from 0 to 4

3. How do you access the third element of a list lst in Python?

o a) lst[3]

o b) lst(3)

o c) lst[2]

o d) lst(1) Answer: c) lst[2]

4. What is the output of the following code: lst = [10, 20, 30, 40]; print(lst[1])?

o a) 10
o b) 20

o c) 30

o d) 40 Answer: b) 20

5. Which function is used to get the length of a list in Python?

o a) length()

o b) size()

o c) len()

o d) count() Answer: c) len()

6. What is the result of len([1, 2, 3, 4])?

o a) 3

o b) 4

o c) 5

o d) 2 Answer: b) 4

7. How can you check if an element is present in a list?

o a) find()

o b) contains()

o c) in

o d) check() Answer: c) in

8. What is the result of 'a' in ['a', 'b', 'c']?

o a) True

o b) False

o c) Error

o d) None Answer: a) True

9. Which of the following is the correct syntax for a for loop that iterates over a list lst?

o a) for i in lst:

o b) loop i over lst:


o c) for lst in i:

o d) while i in lst: Answer: a) for i in lst:

10. Which of the following is a valid list in Python?

o a) {1, 2, 3}

o b) (1, 2, 3)

o c) [1, 2, 3]

o d) <1, 2, 3> Answer: c) [1, 2, 3]

List Operations, List Deletion

11. Which of the following operations adds an element to a list?

o a) list.append()

o b) list.add()

o c) list.concat()

o d) list.insert() Answer: a) list.append()

12. How can you remove an element from a list by its value?

o a) remove()

o b) delete()

o c) pop()

o d) cut() Answer: a) remove()

13. What is the result of lst = [1, 2, 3]; lst.remove(2)?

o a) [1, 3]

o b) [2, 3]

o c) [1, 2]

o d) Error Answer: a) [1, 3]

14. Which method removes the last element from a list?

o a) pop()
o b) remove()

o c) clear()

o d) discard() Answer: a) pop()

15. What does the del statement do to a list?

o a) Deletes the last element

o b) Deletes a specific element by index

o c) Deletes the entire list

o d) Both b and c Answer: d) Both b and c

16. Which method can clear all elements from a list?

o a) remove()

o b) clear()

o c) discard()

o d) delete() Answer: b) clear()

17. What is the output of lst = [1, 2, 3]; del lst[0]; print(lst)?

o a) [1, 2, 3]

o b) [2, 3]

o c) [1, 2]

o d) Error Answer: b) [2, 3]

18. What happens when you try to remove an element from an empty list using pop()?

o a) Nothing

o b) The list becomes None

o c) An IndexError is raised

o d) The list gets cleared Answer: c) An IndexError is raised

19. Which of the following can be used to delete multiple elements from a list by slicing?

o a) del lst[start:end]

o b) remove(start:end)
o c) pop(start:end)

o d) delete(start:end) Answer: a) del lst[start:end]

20. What will be the result of lst = [1, 2, 3]; lst.clear(); print(lst)?

o a) []

o b) None

o c) 1, 2, 3

o d) Error Answer: a) []

Cloning Lists, Nested Lists

21. How do you create a copy of a list lst in Python?

o a) lst.copy()

o b) list(lst)

o c) lst[:]

o d) All of the above Answer: d) All of the above

22. What is the result of lst1 = [1, 2, 3]; lst2 = lst1[:]; lst1.append(4); print(lst2)?

o a) [1, 2, 3]

o b) [1, 2, 3, 4]

o c) None

o d) Error Answer: a) [1, 2, 3]

23. What is the output of lst1 = [1, [2, 3]]; lst2 = lst1[:]; lst2[1].append(4); print(lst1)?

o a) [1, [2, 3]]

o b) [1, [2, 3, 4]]

o c) [2, 3, 4]

o d) Error Answer: b) [1, [2, 3, 4]]

24. Which function is used to create a deep copy of a list (including nested lists)?

o a) copy.deepcopy()
o b) list.copy()

o c) deepcopy()

o d) clone() Answer: a) copy.deepcopy()

25. Which of the following is a nested list?

o a) [1, 2, 3]

o b) [[1, 2], [3, 4]]

o c) [1, [2, 3], 4]

o d) Both b and c Answer: d) Both b and c

26. How can you access the value 2 in the list lst = [[1, 2], [3, 4]]?

o a) lst[0][1]

o b) lst[1][1]

o c) lst[0, 1]

o d) lst[1, 0] Answer: a) lst[0][1]

27. What will be the output of lst = [[1, 2], [3, 4]]; print(len(lst))?

o a) 2

o b) 4

o c) 6

o d) 1 Answer: a) 2

28. What is the result of lst = [1, 2, [3, 4]]; lst[2][1]?

o a) 4

o b) 2

o c) 3

o d) Error Answer: a) 4

Object-Oriented Programming: Classes, Objects, Methods

29. Which of the following correctly defines a class in Python?


o a) class ClassName():

o b) def ClassName():

o c) object ClassName():

o d) class ClassName: Answer: a) class ClassName():

30. Which method is called automatically when an object is created?

o a) __init__

o b) __new__

o c) __create__

o d) __start__ Answer: a) __init__

31. Which of the following is true about methods in Python classes?

o a) They must have at least one argument (self)

o b) They cannot have arguments

o c) They must return a value

o d) They are only callable inside the class Answer: a) They must have at least one
argument (self)

32. How do you create an instance of a class Dog in Python?

o a) Dog()

o b) new Dog()

o c) create Dog()

o d) instantiate Dog() Answer: a) Dog()

33. Which of the following creates an object obj of the class Car?

o a) obj = new Car()

o b) obj = Car()

o c) obj = Car.create()

o d) obj = Car.new() Answer: b) obj = Car()

34. What is the keyword used to access an object's attributes or methods?


o a) .

o b) :

o c) ->

o d) ; Answer: a) .

35. Which method is used to represent an object as a string?

o a) __str__()

o b) __repr__()

o c) __string__()

o d) __reprstr__() Answer: a) __str__()

36. Which of the following is the correct way to define a method inside a class?

o a) def methodName(self):

o b) def methodName():

o c) method methodName(self):

o d) self def methodName(): Answer: a) def methodName(self):

37. How do you define a constructor method in a Python class?

o a) def __init__(self):

o b) def init(self):

o c) class __init__(self):

o d) init(self): Answer: a) def __init__(self):

38. What will be the output of the following code?

python

CopyEdit

class Dog:

def __init__(self, name):

self.name = name
obj = Dog("Buddy")

print(obj.name)

o a) Dog

o b) Buddy

o c) None

o d) Error Answer: b) Buddy

39. How do you define a class attribute in Python?

o a) self.attr = value

o b) attr = value

o c) class.attr = value

o d) __init__.attr = value Answer: b) attr = value

40. Which method is used to delete an object in Python?

o a) __del__()

o b) delete()

o c) remove()

o d) destroy() Answer: a) __del__()

Standard Libraries

41. Which of the following is a standard library in Python?

o a) os

o b) math

o c) random

o d) All of the above Answer: d) All of the above

42. What does the math.sqrt() function do?

o a) Calculates the square of a number

o b) Calculates the square root of a number


o c) Calculates the cube root of a number

o d) Returns an error Answer: b) Calculates the square root of a number

43. Which module is used to work with random numbers in Python?

o a) random

o b) math

o c) os

o d) datetime Answer: a) random

44. Which method is used to generate a random integer in a given range?

o a) randint()

o b) random()

o c) randrange()

o d) choice() Answer: a) randint()

45. How can you get the current working directory using the os module?

o a) os.getcwd()

o b) os.pwd()

o c) os.directory()

o d) os.curdir() Answer: a) os.getcwd()

46. What does the random.choice() function do?

o a) Selects a random element from a list

o b) Selects a random index from a list

o c) Selects the first element from a list

o d) Selects the largest element from a list Answer: a) Selects a random element
from a list

47. Which method from the datetime module returns the current date and time?

o a) datetime.now()

o b) datetime.today()
o c) datetime.current()

o d) datetime.get() Answer: a) datetime.now()

48. What does math.pow(2, 3) return?

o a) 6

o b) 8

o c) 9

o d) 4 Answer: b) 8

49. Which method from the time module makes the program sleep for a given number of
seconds?

o a) time.sleep()

o b) time.delay()

o c) time.wait()

o d) time.pause() Answer: a) time.sleep()

50. Which of the following is used to load a JSON file in Python?

o a) json.load()

o b) json.dumps()

o c) json.loads()

o d) json.parse() Answer: a) json.load()

Unit 5:

Data Structures

1. Which of the following uses the FIFO method?

• A) Stack

• B) Queue

• C) Array

• D) Linked List
Answer: B) Queue

2. Which one of the following is a linear data structure?


• A) Tree

• B) Graph

• C) Queue

• D) None of the above


Answer: C) Queue

3. What is the primary characteristic of a stack?

• A) Last In First Out (LIFO)

• B) First In First Out (FIFO)

• C) Random Access

• D) Ordered
Answer: A) Last In First Out (LIFO)

4. Which data structure allows duplicate elements?

• A) Set

• B) Stack

• C) Queue

• D) Both B and C
Answer: D) Both B and C

5. In which data structure is the insertion and deletion performed at opposite ends?

• A) Stack

• B) Queue

• C) Linked List

• D) Array
Answer: B) Queue

6. Which of the following is not a type of linked list?

• A) Singly Linked List

• B) Doubly Linked List

• C) Circular Linked List


• D) Static Linked List
Answer: D) Static Linked List

7. What is the time complexity for accessing an element in an array?

• A) O(n)

• B) O(log n)

• C) O(1)

• D) O(n log n)
Answer: C) O(1)

8. Which data structure is used for implementing recursion?

• A) Queue

• B) Stack

• C) Array

• D) Tree
Answer: B) Stack

9. What is the maximum number of nodes in a binary tree of height h?

• A) 2h2h

• B) 2h+1−12h+1−1

• C) h2h2

• D) h+1h+1
Answer: B) 2h+1−12h+1−1

10. Which of the following is a non-linear data structure?

• A) Array

• B) Stack

• C) Queue

• D) Tree
Answer: D) Tree

Searching Algorithms
11. What is the time complexity of linear search in the worst case?

• A) O(1)

• B) O(log n)

• C) O(n)

• D) O(n log n)
Answer: C) O(n)

12. In which scenario can binary search be applied?

• A) Unsorted array

• B) Sorted array

• C) Linked list

• D) None of the above


Answer: B) Sorted array

13. What is the average time complexity of binary search?

• A) O(1)

• B) O(n)

• C) O(log n)

• D) O(n log n)
Answer: C) O(log n)

14. Which of the following searching algorithms is not efficient for large datasets?

• A) Linear Search

• B) Binary Search

• C) Jump Search

• D) Interpolation Search
Answer: A) Linear Search

15. What does binary search require for it to work correctly?

• A) The array must be sorted.

• B) The array must be unsorted.


• C) The elements must be unique.

• D) None of the above


Answer: A) The array must be sorted.

Sorting Algorithms

16. What is the worst-case time complexity of bubble sort?

• A) O(n)

• B) O(n log n)

• C) O(n^2)

• D) O(log n)
Answer: C) O(n^2)

17. Which sorting algorithm is considered to be stable?

• A) Quick Sort

• B) Heap Sort

• C) Merge Sort

• D) Selection Sort
Answer: C) Merge Sort

18. What is the best-case time complexity for insertion sort?

• A) O(n^2)

• B) O(n log n)

• C )O(1)
– D )O(n)
**Answer: **D )O(n)

19. Which sorting algorithm divides the dataset into smaller sub-arrays to sort them
recursively?
- A )Bubble Sort
- B )Insertion Sort
- C )Quick Sort
- D )Selection Sort
**Answer: **C )Quick Sort
20. Selection sort works by repeatedly selecting which element?
- A )The largest
- B )The smallest
- C )The middle
- D )The first
**Answer: **B )The smallest

21. Which sorting algorithm has a time complexity of O(n log n)?
- A )Bubble Sort
- B )Insertion Sort
- C )Merge Sort
- D )Selection Sort
**Answer: **C )Merge Sort

22. What type of sorting does not require additional memory space?
- A )Merge Sort
- B )Quick Sort
- C )Bubble Sort
- D )Heap Sort
**Answer: **C )Bubble Sort

23. Which algorithm sorts by repeatedly swapping adjacent elements if they are in the
wrong order?
- A )Insertion Sort
- B )Selection Sort
- C )Bubble Sort
- D )Merge Sort
**Answer: **C )Bubble Sort

24. What is a characteristic feature of selection sort?


- A )It requires additional space for sorting.
–B )It sorts in place.
–C )It’s always faster than bubble sort.
–D )It can only sort integers.
–Answer: B) It sorts in place.

25. Which sorting algorithm is not comparison-based?


–A )Merge Sort
–B )Heap Sort
–C )Counting Sort
–D )Quick Sort
–Answer: C) Counting Sort.

Additional Questions on Data Structures, Searching, and Sorting

26. The time complexity for deleting an element from a linked list is:
–A )O(1)
–B )O(n)
–C )O(log n)
–D )O(n log n)
–Answer: B) O(n).

27. In which data structure can you implement a priority queue efficiently?
–A )Array
–B )Linked List
–C )Heap
–D )Stack
–Answer: C) Heap.

28. Which type of search algorithm uses divide and conquer strategy?
–A )Linear Search
–B )Binary Search
–C )Jump Search
–D )Interpolation Search
–Answer: B) Binary Search.

29. In which case would you prefer insertion sort over other algorithms?
–A )When the dataset is large.
–B )When the dataset is small and almost sorted.
–C )When memory space is limited.
–D )None of the above.
–Answer: B) When the dataset is small and almost sorted.

30. What does it mean if an algorithm has a time complexity of O(1)?


–A )It takes constant time regardless of input size.
–B )It takes linear time based on input size.
–C )It takes logarithmic time based on input size.
–D )It takes quadratic time based on input size.
–Answer: A) It takes constant time regardless of input size.

31. How does merge sort achieve its efficiency?


–A )By using random access memory efficiently.
–B )By dividing arrays into halves recursively and merging them back.
–C )By using iterative comparisons only.
–D )By minimizing memory usage during sorting.
–Answer: B) By dividing arrays into halves recursively and merging them back.

32. The worst-case scenario for quicksort occurs when:


–A )(The pivot divides arrays into equal halves every time.)
–B )(The pivot always results in one empty sub-array.)
–C )(All elements are identical.)
–D )(The array is already sorted.)
–Answer: B) The pivot always results in one empty sub-array.

33. What type of data structure would you use to implement depth-first search (DFS)?
–A )(Queue.)
–B )(Stack.)
–C )(Array.)
–D )(Linked List.)
—Answer: B) Stack.

34. In which scenario would you use a hash table instead of an array?
—A )(When you need to maintain order.)
—B )(When you need fast lookups.)
—C )(When you have limited memory.)
—D )(When you need to store duplicate values.)
—Answer: B) When you need fast lookups.

35. For which operation does a doubly linked list provide better performance than a singly
linked list?
—A )(Insertion at head.)
—B )(Deletion at tail.)
—C )(Traversal from head to tail.)
—D )(Accessing middle elements.)
—Answer: B) Deletion at tail.

36. Which sorting algorithm has a best-case performance that can be linear (O(n)) under
certain conditions?
—A )(Bubble sort.)
—B )(Insertion sort.)
—C )(Selection sort.)
—D )(Merge sort.)
—Answer: B) Insertion sort.

37. In a binary search tree, what property must hold true for each node's left and right
children?
—A )(Left child < parent < right child.)
—B )(Left child > parent > right child.)
—C )(Left child = parent = right child.)
—D )(Left child < parent > right child.)
—Answer: A) Left child < parent < right child.

38. Which searching algorithm can be used on both sorted and unsorted lists but performs
better on sorted lists?
—A )(Linear search.)
—B )(Binary search.)
—C )(Jump search.)
—D )(Exponential search.)
—Answer: C) Jump search.

39. What kind of data structure would you use to implement breadth-first search (BFS)?
—A )(Stack.)
—B )(Queue.)
—C )(Array.)
—D )(Linked List.)
—Answer: B) Queue.

40. What does it mean if a sorting algorithm is "in-place"?


—A )(It requires no additional storage space for sorting.)
—B )(It sorts without modifying original data structures.)
—C )(It only works with integer values.)
—D )(It can only handle small datasets efficiently.)
—Answer: A) It requires no additional storage space for sorting.

41. For which operation do hash tables provide average-case constant time complexity
(O(1))?
—A)(Insertion.)
—B)(Search.)
—C)(Deletion.)
—D)(All of the above.)
—Answer: D) All of the above.
42. In quicksort, what happens if all elements are identical during partitioning?
—A)(The algorithm will run efficiently.)
—B)(It will lead to maximum recursion depth.)
—C)(It will always choose one element as pivot.)
—D)(None of the above.)
—Answer: B) It will lead to maximum recursion depth.

43. How does heap sort achieve its efficiency compared to other algorithms like bubble or
selection sort?
—A)(By using less memory.)
—B)(By maintaining a balanced tree structure.)
—C)(By performing fewer comparisons.)
—D)(By using randomization.)
—Answer: B) By maintaining a balanced tree structure.

44. What type of data structure allows for fast insertion and deletion from both ends but
not random access?
—A)(Array.)
—B)(Linked List.)
—C)(Deque.)
—D)(Hash Table.)
—Answer: C) Deque.

45. What happens when an attempt to insert an element into a full stack occurs?
--A)(The stack overflows.)
--B)(The stack shrinks.)
--C)(The stack becomes empty.)
--D)(Nothing happens; it remains full.)
--Answer: A) The stack overflows.

46. What type of problem does dynamic programming solve?


--A)(Problems that can be solved using greedy methods.)
--B)(Problems that can be broken down into overlapping subproblems.)
--C)(Problems with no optimal solution.)
--D)(All types of problems.)
--Answer: B) Problems that can be broken down into overlapping subproblems.

47. What type of tree allows for efficient searching, insertion, and deletion?
--A)(Binary Tree.)
--B)(Binary Search Tree.)
--C)(AVL Tree.)
--D)(Both B and C.)
--Answer: D) Both B and C.

48. Which data structure would you use to implement undo functionality in applications?
--A)(Queue.)
--B)(Stack.)
--C)(ArrayList.)
--D)(Hash Table.)
--Answer: B) Stack.

49. Which type of sorting algorithm divides data into two parts, sorts them separately, and
then merges them?
--A)(QuickSort.)
--B)(MergeSort.)
--C)(HeapSort.)
--D)(BubbleSort.)
--Answer: B) MergeSort.

50. What do we call an algorithm that solves problems by combining solutions to


subproblems?
--A)(Greedy Algorithm.)
--B)(Dynamic Programming Algorithm.)
--C)(Divide-and-Conquer Algorithm.)
--D)(Backtracking Algorithm.)
--Answer: C) Divide-and-Conquer Algorithm.

You might also like