Venus Python Programming 1
Chapter 1 (a) It denotes the block of code and improves
readability
(b) It is optional and does not affect the code
Fundamental Concepts (c) It is used for syntax highlighting
(d) It is used to separate statements
Ans.(a)
Multiple ChoiCe Question
10. Why are meaningful variable names important in
1. Who is known as the creator of Python?
Python programming?
(a) Guido van Rossum (b) Dennis Ritchie
(a) They improve code readability and maintainbility
(c) Bjarne Stroustrup (d) James Gosling
(b) They make the code run faster
Ans.(a)
(c) They are required for the code to compile
2. What are the main features of Python?
(d) They are a best practice
(a) Easy to read, write and maintain; extensive
Ans.(a)
standard library; dynamic typing
11. What is the purpose of the import statement in
(b) Static typing, complex syntax, limited standard
Python?
library
(a) To include external modules or libraries
(c) Difficult to learn, limited community support
(b) To define a new function
(d) None of the above
(c) To assign a value to a variable
Ans.(a)
(d) To print output to the console
3. Which Python distribution is known for its ease of
Ans.(a)
use and extensive standard library?
12. Which of the following is true about Python’s None
(a) Anaconda (b) Miniconda
value?
(c) CPython (d) Jython
(a) It is equivalent to zero
Ans.(a)
(b) It is equivalent to an empty string
4. Which version of Python introduced the ‘walrus
(c) It represents the absence of a value
operator’ (:=)?
(d) It represents infinity
(a) Python 3.8 (b) Python 3.7
Ans.(c)
(c) Python 3.6 (d) Python 3.5
13. What does the range() function in Python return?
Ans.(a)
(a) A list of integers
5. Name a popular Python IDE used for software
(b) A tuple of integers
development.
(c) A dictionary of integers
(a) PyCharm (b) Eclipse
(d) An iterator of integers
(c) Visual Studio Code (d) Net Beans
Ans.(d)
Ans.(a)
14. Which of the following is a correct way to create a
6. What is the purpose of a Python interpreter?
list in Python?
(a) To execute Python code line by line
(a) list = {1, 2, 3} (b) list = [1, 2, 3]
(b) To compile Python code into machine code
(c) list = (1, 2, 3) (d) list = “1, 2, 3”
(c) To debug Python code
Ans.(b)
(d) To format Python code
15. What is the output of the following code?
Ans.(a)
python
7. Which symbol is used for single-line comments in
Copy code
Python?
(a) 2.5 (b) 2 (c) 2.0 (d) 2.2
(a) # (b) // (c) /* (d) //
Ans.(b)
Ans.(a)
16. What is the purpose of the strip() method in Python?
8. What is the recommended way to debug Python
(a) To remove leading and trailing spaces from a string
code?
(b) To split a string into a list
(a) Using the built-in debugger or print statements
(c) To concatenate two strings
(b) Using breakpoints
(d) To convert a string to uppercase
(c) Using logging statements
Ans.(a)
(d) All of the above
17. Which of the following is a correct way to open a file
Ans.(a)
in Python for reading?
9. What is the significance of indentation in Python?
(a) file = open(“file.txt”, “w”)
Venus Python Programming 2
(b) file = open(“file.txt”, “r”) Chapter 2
(c) file = open(“file.txt”, “a”)
(d) file = open(“file.txt”, “x”0
Basics I/O operations
Ans.(b)
18. What is the output of the following code?
python Multiple ChoiCe Question
Copy code 1. What is the function of the input() function in
(a) [1, 2, 3] (b) [1, 2, 3, 4] Python?
(c) [1, 2, 3, 4, 4] (d) [1, 2, 3, 4, 4, 4] (a) Display output (b) Take user input
Ans.(b) (c) Perform mathematical operations
19. What is the purpose of the zip() function in Python? (d) Define a variable
(a) To compress files (b) To unzip files Ans.(b)
(c) To iterate over two or more lists in parallel 2. Which function is used to take user input as a string
(d) To concatenate strings in Python 2.x?
Ans.(c) (a) input() (b) raw_input()
20. What is the output of the following code? (c) user_input() (d) read_input()
python Ans.(b)
Copy code 3. What is the function of the print() function in
(a) x is greater than 10 (b) x is less than 10 Python?
(c) x is less than or equal to 10 (a) Take user input (b) Display output
(d) x is greater than or equal to 10 (c) Perform mathematical operations
Ans.(c) (d) Define a variable
Ans.(b)
4. Which of the following is a scalar type in Python?
(a) List (b) Tuple
(c) Numeric (d) Dictionary
Ans.(c)
5. How can you format output in Python?
(a) Using the format() method
(b) Using the % operator
(c) Using f-strings
(d) All of the above
Ans.(d)
6. What is the purpose of the bytes data type in
Python?
(a) Store text data (b) Store binary data
(c) Store numeric data (d) Store boolean data
Ans.(b)
7. What is type casting in Python?
(a) Converting a variable to a different data type
(b) Defining a new variable
(c) Performing arithmetic operations
(d) Comparing two variables
Ans.(a)
8. Which of the following is a comparison operator in
Python?
(a) + (b) – (c) * (d) = =
Ans.(d) = =
9. What is the result of the expression 5%2 in Python?
(a) 2 (b) 2.5 (c) 0.5 (d) 1
Ans.(d)
10. How can you perform bitwise operations in Python?
Venus Python Programming 3
(a) Using &, |, ^, ~, <>, >> operators Ans.(b)
(b) Using and, or, not keywords 21. What is the result of the expression 2 + 3 * 4 in
(c) Using bit_and, bit_or, bit_not functions Python?
(d) None of the above (a) 14 (b) 20 (c) 18 (d) 5
Ans.(a) Ans.(c)
11. What is the output of the expression 2**3 in Python? 10. What is the result of the expression 10/3 in Python?
(a) 5 (b) 6 (c) 8 (d) 16 (a) 3.333 (b) 3 (c) 3.0 (d) 3.3333....
Ans.(c) Ans.(a)
12. What is the output of the expression 4//3 in Python? 23. What is the output of the expression 7//3 in Python?
(a) 1 (b) 1.333 (c) 1.0 (d) 0.75 (a) 2.333 (b) 2 (c) 2.0 (d) 2.3333...
Ans.(a) Ans.(b)
13. Which of the following is not a valid variable name 24. What is the result of the expression 5%2 in Python?
in Python? (a) 2 (b) 2.5 (c) 0.5 (d) 1
(a) my_variable (b) 123_variable Ans.(d)
(c) _variable (d) variable123 25. What is the output of the expression 2**3 in Python?
Ans.(b) (a) 5 (b) 6 (c) 8 (d) 16
14. What is the result of the expression True and False Ans.(c)
in Python? 26. What is the result of the expression 4**0.5 in
(a) True (b) False Python?
(c) None (d) Error (a) 2 (b) 1.414 (c) 2.0 (d) Error
Ans.(b) Ans.(b)
15. What is the result of the expression True or False in 27. What is the output of the expression 4//3.0 in
Python? Python?
(a) True (b) False (a) 1.333 (b) 1 (d) 1.0 (d) 0.75
(c) None (d) Error Ans.(c)
Ans.(a) 28. What is the result of the expression not (True or
16. What is the result of the expression not True in False) in Python?
Python? (a) True (b) False (c) None (d) Error
(a) True (b) False Ans.(b)
(c) None (d) Error 29. Which of the following is a valid way to create a list
Ans.(b) in Python?
17. Which of the following is a valid way to create a (a) [1, 2, 3, 4] (b) (1, 2, 3, 4)
multiline string in Python? (c) {1, 2, 3, 4} (d) 1, 2, 3, 4
(a) Using single quotes (‘) Ans.(a)
(b) Using double quotes (“) 30. What is the result of the expression sum([1, 2, 3, 4])
(c) Using triple quotes (‘’’ or “””) in Python?
(d) All of the above (a) 10 (b) 24 (c) 6 (d) 4
Ans.(c) Ans.(a)
18. What is the result of the expression len(“Hello”) in
Python?
(a) 5 (b) 6 (c) 4 (d) Error
Ans.(a)
19. What is the output of the expression str(123) in
Python?
(a) 123 (b) “123” (c) ‘123’ (d) Error
Ans.(c)
20. Which of the following is not a valid way to
comment in Python?
(a) #This is a comment (b) /*This is a comment*/
(c) ‘‘‘This is a comment’’’
(d) “““This is a comment”””
Venus Python Programming 4
Chapter 3 Copy code
(a) Greater than 10 (b) Greater than 5
(c) Less than or equal to 5 (d) Syntax error
Control Flow: Conditional blocks
Ans.(c)
9. How do you add an alternative code block to an if
Multiple ChoiCe Question statement in Python?
1. What is the purpose of a conditional block in (a) Using the else keyword
programming? (b) Using the elif keyword
(a) To execute a set of statements only if a certain (c) Using the or operator
condition is true (d) Using parentheses ()
(b) To repeat a set of a statements multiple times Ans.(b)
(c) To store multiple values in a single variable 10. What is the purpose of the else keyword in an if
(d) To define a function statement?
Ans.(a) (a) To indicate the end of the if statement
2. Which keyword is used to start an if statement in (b) To provide an alternative condition to check
Python? (c) To execute a code block only if the condition is false
(a) if (b) else (c) elif (d) then (d) To iterate over a sequence
Ans.(a) Ans.(c)
3. What is the general format of an if statement in 11. How do you write a conditional block in Python?
Python? (a) Using the if statement
(a) if condition {code block} (b) Using for loop
(b) if condition : code block (c) Using the while loop
(c) if condition then {code block} (d) Using the do-while loop
(d) if {code block} condition Ans.(a)
Ans.(b) 12. What is the purpose of the if statement in Python?
4. How do you denote a code inside an if statement in (a) To execute a set of statements only if a certain
Python? condition is true
(a) Indentation (b) Curly braces {} (b) To repeat a set of statements multiple times
(c) Parentheses () (d) Square brackets [] (c) To define a new function
Ans.(a) (d) To store multiple values in a single variable
5. What is the purpose of the elif keyword in Python? Ans.(a)
(a) To define a new function 13. Which of the following is the correct syntax for an if
(b) To indicate the end of an if statement statement in Python?
(c) To provide an alternative condition to check (a) if (condition) {code block}
(d) To iterate over a sequence (b) if condition then {code block}
Ans.(c) (c) if condition : code block
6. How do you write a multiway branching in Python? (d) if {code block} condition
(a) Using multiple if statements Ans.(c)
(b) Using the switch statement 14. How do you denote a code block inside an if
(c) Using the elif keyword statement in Python?
(d) Using the or operator (a) Curly braces {} (b) Indentation
Ans.(c) (c) Parentheses () (d) Square brackets []
7. Which of the following statements is true about the Ans.(b)
if statement? 15. What does the elif keyword do in Python?
(a) It can only have one condition (a) Indicates the end of an if statement
(b) It can have multiple conditions using elif (b) Provides an alternative condition to check
(c) It can have multiple conditions using and/or (c) Defines a new function
operators (d) Iterates over a sequence
(d) It can only be used inside a loop Ans.(b)
Ans.(c) 16. What is the purpose of multiway branching in
8. What will be the output of the following code? programming?
bash (a) To execute a set of statements only if a certain
Venus Python Programming 5
condition is true 24. How do you denote a code block inside an if
(b) To provide an alternative condition to check statement in Python?
(c) To repeat a set of statements multiple times (a) Curly braces {} (b) Indentation
(d) To store multiple values in a single variable (c) Parentheses () (d) Square brackets []
Ans.(b) Ans.(b)
17. Which of the following statements is true about the 25. What does the elif keyword do in Python?
elif keyword in Python? (a) Indicates the end of an if statement
(a) It can only be used once in an if statement (b) Provides an alternative condition to check
(b) It must always be followed by an else block (c) Defines a new function
(c) It can have multiple elif blocks in an if statement (d) Iterates over a sequence
(d) It can only be used inside a loop Ans.(b)
Ans.(c) 26. What is the purpose of multiway branching in
18. What will be the output of the following code? programming?
bash (a) To execute a set of statements only if a certain
Copy code condition is true
(a) Greater than 10 (b) Greater than 5 (b) To provide an alternative condition to check
(c) Less than or equal to 5 (d) Syntax error (c) To repeat a set of statements multiple times
Ans.(c) (d) To store multiple values in single variable
19. How do you add an else block to an if statement in Ans.(b)
Python? 27. Which of the following statements is true about the
(a) Using the else keyword elif keyword in Python?
(b) Using the elif keyword (a) It can only be used once in an if statement
(c) Using the or operator (b) It must always be followed by an else block
(d) Using parentheses () (c) It can have multiple elif blocks in an if statement
Ans.(a) (d) It can only be used inside a loop
20. What is the purpose of the else keyword in an if Ans.(c)
statement? 28. What will be the output of the following code?
(a) To indicate the end of the if statement bash
(b) To provide an alternative condition to check Copy code
(c) To execute a code block only if the condition is false (a) Greater than 10 (b) Greater than 5
(d) To iterate over a sequence (c) Less than or equal to 5 (d) Syntax error
Ans.(c) Ans.(c)
21. How do you write a conditional block in Python? 29. How do you add an else block to an if statement in
(a) Using the if statement Python?
(b) Using the for loop (a) Using the else keyword (b) Using the elif keyword
(c) Using the while loop (c) Using the or operator (d) Using parentheses ()
(d) Using the do-while loop Ans.(a)
Ans.(a) 30. What is the purpose of the else keyword in an if
22. What is the purpose of the if statement in Python? statement?
(a) To execute a set of statements only if a certain (a) To indicate the end of the if statement
condition is true (b) To provide an alternative condition to check
(b) To repeat a set of statements multiple times (c) To execute a code block only if the condition is false
(c) To define a new function (d) To iterate over a sequence
(d) To store multiple values in a single variable Ans.(c)
Ans.(a)
23. Which of the following is the correct syntax for an if
statement in Python?
(a) if (condition) {code block}
(b) if condition then {code block}
(c) if condition : code block
(d) if {code block} condition
Ans.(c)
Venus Python Programming 6
Chapter 4 Ans.(d)
9. What will be the output of the following code?
python
Functions in Python
Copy code
(a) 2 (b) 5
Multiple ChoiCe Question (c) 10 (d) None of the above
1. Which keyword is used to define a function in Ans.(c)
Python? 10. Which of the following is true about the return
(a) func (b) def statement in Python functions?
(c) function (d) define (a) It exits the function and returns a value
Ans.(b) (b) It must always return a value
2. What will be the output of the following code? (c) It is optional
python (d) Both a and c
Copy code Ans.(d)
(a) 5 (b) 23 (c) None (d) Error 11. What will be the output of the following code?
Ans.(a) python
3. Which of the following is a lambda function? Copy code
(a) lambda x, y : x + y (a) 7 (b) 12 (c) 1 (d) Error
(b) def lambda (x, y) : return x + y Ans.(b)
(c) function (x, y) = x + y 12. What is the correct syntax to define a function with
(d) def(x, y) : return x + y variable-length arguments?
Ans.(a) (a) def func(*args) : (b) def func(args*) :
4. What is the scope of a variable declared inside a (c) def func(*args*) : (d) def func(*arg) :
function? Ans.(a)
(a) Global (b) Local 13. Which of the following is true about lambda
(c) Both a and b (d) None of the above functions?
Ans.(b) (a) They can have multiple expressions
5. What does the following code return? (b) They can have multiple statements
python (c) They can have only one expression
Copy code (d) They cannot have any expressions
(a) [1][1] (b) [1][1, 1] Ans.(c)
(c) [1, 1][1, 1] (d) Error 14. What will be the output of the following code?
Ans.(b) python
6. Which of the following statements is true about Copy code
function arguments in Python? (a) [2] [3] (b) [2] [2, 3]
(a) Functions in Python cannot have default arguments (c) [2] [2, 2] (d) [3] [2, 3]
(b) Functions in Python can have deault arguments Ans.(b)
(c) Functions in Python must have at least one 15. Which of the following is true about the global
argument keyword?
(d) Functions in Python cannot return multiple values (a) It is used to declare a global variable inside a
Ans.(b) function
7. What is the output of the following code (b) It is used to define a function as global
python (c) It is used to define a function parameter as global
Copy code (d) It is used to import global variables
(a) 5 (b) 10 Ans.(a)
(c) 15 (d) None of the above 16. What is the purpose of the nonlocal keyword?
Ans.(c) (a) To declare a variable as global
8. What is a lambda function? (b) To declare a variable as local
(a) A function defined using the lambda keyword (c) To declare a variable in the nearest enclosing scope
(b) A function that does not have a name (d) To declare a variable in the local scope
(c) A function that takes no arguments Ans.(c)
(d) Both a and b 17. Which of the following is a valid function definition
Venus Python Programming 7
in Python? variable-length arguments?
(a) def func x, y : return x + y (a) It can accept a variable number of positional
(b) def func (x, y) : return x + y arguments
(c) def func (x, y) return x + y (b) It can accept a variable number of keyword
(d) def func (x, y) x + y arguments
Ans.(b) (c) It can accept both positional and keyword arguments
18. What will be the output of the following code? (d) All of the above
python Ans.(d)
Copy code 27. What will be the output of the following code?
(a) (8, 2) (b) 8, 2 python
(c) [8, 2] (d) (5, 3) Copy code
Ans.(a) (a) 3 (b) 10 (c) 6 (d) Error
19. What is a recursive function? Ans.(b)
(a) A function that calls another function 28. What is the output of the following code?
(b) A function that calls itself python
(c) A function that never ends Copy code
(d) A function that is defined inside another function (a) 16 (b) 4 (c) –16 (d) –4
Ans.(b) Ans.(b)
20. What will be the output of the following code? 29. What is the default return value of a function that
python does not have a return statement?
Copy coed (a) 0 (b) None (c) False (d) Null
(a) 24 (b) 20 (c) 16 (d) 12 Ans.(b)
Ans.(a) 30. What will be the output of the following code?
21. What is the purpose of the docstring in Python? python
(a) To provide documentation for a module, class, or Copy code
function (a) 7 (b) 6 (c) 5 (d) 4
(b) To execute a string as a Python code Ans.(a)
(c) To print a string in the console
(d) To define a function parameter
Ans.(a)
22. Which of the following will correctly return multiple
values from a function?
(a) return a, b (b) return [a, b]
(c) return (a, b) (d) All of the above
Ans.(d)
23. What will be the output of the following code?
python
Copy code
(a) 6 (b) 9 (c) 8 (d) Error
Ans.(b)
24. Which of the following is not a valid Python
function name?
(a) func1 (b) _func
(c) 1func (d) func_
Ans.(c)
25. What will be the output of the following code?
python
Copy code
(a) 6, 10 (b) 6, 6
(c) 0, 10 (d) Error
Ans.(a)
26. Which of the following is true about a function with
Venus Python Programming 8
Chapter 5 (c) tuple[0] (d) tuple[–1]
Ans.tuple[1]
9. Tuple Slicing : What does the expression tuple[2:4]
Data Collections return in Python?
(a) A tuple containing the second and third elements
Multiple ChoiCe Question (b) A tuple containing the third and fourth elements
1. Mutability Concept : Which statement best describes (c) A tuple containing elements from index 2 to 4
mutability in Python? (exclusive)
(a) Mutable objects can be changed after creation (d) A tuple containing elements from index 2 to the end
(b) Immutable objects can be changed after creation Ans.(b)
(c) Mutable objects cannot be changed after creation 10. Set Operations : Which set operation in Python
(d) Immutable objects cannot be changed after creation returns elements that are common to both sets?
Ans.(a) (a) union () (b) intersection ()
2. Set Declaration : How are sets declared in Python? (c) difference () (d) symmetric difference()
(a) Using square brackets [ ] Ans.(b)
(b) Using curly braces { } 11. Set Comprehension : Which of the following
(c) Using parentheses ( ) statements correctly creates a set using set
(d) Using angle brackets < > comprehension in Python?
Ans.(b) (a) my_set = {x for x in range(5)}
3. Set Features : What feature distinguishes a set from (b) my_set = {x : x**2 for x in range(5)}
other data structres in Python? (c) my_set = {x**2 for x in range(5)}
(a) Allows duplicate elements (d) my_set = {x for x in range(5) if x% 2 = = 0}
(b) Maintains elements in order of insertion Ans.(a)
(c) Contains only unique elements 12. Set Operations : Which set operation in Python
(d) Stores elements as key-value pairs returns elements that are in either of the sets, but
Ans.(c) not both?
4. Tuple Features : Which of the following statements (a) union () (b) intersection ()
is true about tuples in Python? (c) difference () (d) symmetric difference()
(a) Tuples are mutable Ans.(d)
(b) Tuples can contain duplicate elements 13. Tuple Unpacking : What does the following code
(c) Tuples are ordered collections snippet do in Python?
(d) Tuples are created using square brackets [ ] python
Ans.(c) Copy code
5. Nested Tuples : How are nested tuples initialized in (a) Creates a tuple with elements 1, 2 and 3
Python? (b) Unpacks the tuple into variables x, y and z
(a) (1, (2, 3), 4) (b) [1, [2, 3], 4] (c) Adds elements 1, 2 and 3 to an existing tuple
(c) {1, {2, 3}, 4} (d) (1, {2, 3}, 4) (d) Concatenates elements 1, 2 and 3 into a string
Ans.(a) Ans.(b)
6. Set Initialization : Which of the following is the 14. Tuple Built-in Functions : Which built-in function
correct way to initialize a set in Python with elements in Python returns the index of the first occurrence
1, 2 and 3? of a value in a tuple?
(a) set = {1, 2, 3} (b) set = (1, 2, 3) (a) count () (b) index ()
(c) set = [1, 2, 3] (d) set = {1 : ‘a’, 2 : ‘b’, 3 : ‘c’} (c) len () (d) max ()
Ans.(a) Ans.(b)
7. Tuple Declaration : Which of the following is the 15. Nested Tuple Access : How do you access the
correct way to declare a tuple in Python? second element of the nested tuple ((1, 2), (3, 4)) in
(a) tuple = (1, 2, 3) (b) tuple = {1, 2, 3} Python?
(c) tuple = [1, 2, 3] (d) tuple = 1, 2, 3 (a) ((1, 2), (3, 4)) [1][0] (b) ((1, 2), (3, 4)) [0] [1]
Ans.(a) (c) ((1, 2), (3, 4)) [1, 0] (d) ((1, 2), (3, 4)) [0, 1]
8. Tuple Indexing : How do you access the second Ans.(b)
element of a tuple in Python? 16. Set Declaration with Duplicate Elements : What
(a) tuple[1] (b) tuple[2] happens if you try to create a set with duplicate
Venus Python Programming 9
elements in Python? Ans.(c)
(a) Python raises an error 23. Set Membership Test : How do you test if an
(b) The set is created with duplicate elements element is present in a set in Python?
(c) The duplicate elements are automatically removed (a) Using the present() method
(d) It depends on the method used to create the set (b) Using the contains() method
Ans.(c) (c) Using the in keyword
17. Tuple Concatenation : How do you concatenate two (d) Using the exists() method
tuples in Python? Ans.(c)
(a) Using the + operator (b) Using the * operator 24. Tuple Unpacking with Asterisk : What does the
(c) Using the . operator following code snippet do in Python?
(d) Using the concate() method python
Ans.(a) Copy code
18. Set Intersection Update : What does the intersection_ (a) Assigns 1 to a, 2 to b, and 5 to c
update() method do in Python? (b) Assigns 1 to a, [2, 3, 4] to b and 5 to c
(a) Updates the set with the intersection of itself and (c) Assigns 1 to a, 5 to b, and 5 to c
another set (d) Raises an error
(b) Returns a new set with the intersection of two sets Ans.(b)
(c) Updates the set with the union of itself and another 25. Set Removal : How do you remove an element from
set a set in Python?
(d) Returns a new set with the union of two sets (a) Using the remove() method
Ans.(a) (b) Using the delete() method
19. Tuple Packing : Which of the following statements (c) Using the discard() method
demonstrates tuple packing in Python? (d) Using the pop() method
(a) x, y = (1, 2) (b) (x, y) = 1, 2 Ans.(a)
(c) x, y = 1, 2 (d) (x, y) = (1, 2) 26. Tuple Comparison : How are tuples compared in
Ans.(c) Python?
20. Set Difference Operation : What does the (a) Tuples are compared element-wise
difference() method do in Python? (b) Tuples are compared based on their lengths
(a) Returns the difference between two sets (c) Tuples cannot be compared in Python
(b) Updates the set with the difference between itself (d) Tuples are compared based on their sum
and another set Ans.(a)
(c) Returns the union of two sets 27. Set Operations : What does the clear() method do in
(d) Updates the set with the union of itself and another Python?
set (a) Deletes the set
Ans.(a) (b) Removes all elements from the set
21. Set Operations : What does the symmetric (c) Returns a new empty set
difference_update() method do in Python? (d) Returns the number of elements in the set
(a) Updates the set with the symmetric difference of Ans.(b)
itself and another set 28. Tuple Concatenation : How do you concatenate two
(b) Returns a new set with the symmetric difference of tuples in Python without using the + operator?
two sets (a) tuple1.concat(tuple2) (b) concat(tuple1, tuple2)
(c) Updates the set with the intersection of itself and (c) tuple1.extend(tuple2) (d) tuple1.join(tuple2)
another set Ans.(c)
(d) Returns a new set with the intersection of two sets 29. Set Intersection Update : Which method in Python
Ans.(a) updates a set with the intersection of itself and
22. Tuple Immutability : What is the significance of tuple another set?
immutability in Python? (a) intersect_update () (b) update_intersection()
(a) Tuples can be modified after creation (c) intersection_update() (d) set_intersection()
(b) Tuples are faster than lists for modification Ans.(c)
operations 30. Tuple Assignment : How do you swap the values of
(c) Tuples can be used as keys in dictionaries two variables a and b using tuples in Python?
(d) Tuples consume less memory than lists (a) (b, a) = (a, b) (b) (a, b) = (b, a)
Venus Python Programming 10
(c) [a, b] = [b, a] (d) {a, b} = {b, a} Chapter 6
Ans.(b)
List
Multiple ChoiCe Question
1. Which of the following is the correct way to declare
a list in Python?
(a) list = {1, 2, 3} (b) list = (1, 2, 3)
(c) list = [1, 2, 3] (d) list = “1, 2, 3”
Ans.(c)
2. Which method is used to add an element at the end
of a list?
(a) add() (b) append ()
(c) insert () (d) extend ()
Ans.(b)
3. What will be the output of the following code? print
([1, 2, 3] + [4, 5])
(a) [1, 2, 3, 4, 5] (b) [5, 7, 8]
(c) [1, 2, 3, 5, 4] (d) Error
Ans.(a)
4. Which method removes the first occurrence of a
value from a list?
(a) remove () (b) pop ()
(c) delete () (d) discard ()
Ans.(a)
5. Which of the following is not a built-in function for
lists?
(a) len() (b) sort ()
(c) max() (d) join()
Ans.(d)
6. How can you access the third element of a list named
my_list?
(a) my_list[2] (b) my_list[3]
(c) my_list[0] (d) my_list[–1]
Ans.(a)
7. Which function would you use to get the number of
items in a list?
(a) count() (b) length()
(c) len() (d) size()
Ans.(c)
8. What does the extend() method do?
(a) Adds its argument as a single element to the end of
the list
(b) Adds elements of its argument to the list
(c) Replaces the last element with its argument
(d) Removes the last element from the list
Ans.(b)
9. What will be the output of the following code? my_list
= [1, 2, 3]; my_list.insert(1, ‘a’); print(my_list)
(a) [1, 2, 3, ‘a’’] (b) [1, ‘a’, 2, 3]
(c) [1, 2, ‘a’, 3] (d) [‘a’, 1, 2, 3]
Venus Python Programming 11
Ans.(b) Chapter 7
10. Which list method is used to reverse the order of
elements? Dictionary
(a) reverse() (b) invert()
(c) revert() (d) swap() Multiple ChoiCe Question
Ans.(a) 1. Which of the following is a correct way to declare a
list in Python?
(a) ‘list = {}’ (b) ‘list = ()’
(c) ‘list = []’ (d) ‘list = | |’
Ans.(c)
2. What will be the output of ‘len([1, 2, 3, 4])’?
(a) 3 (b) 4 (c) 5 (d) 2
Ans.(b)
3. How can you add an element to the end of a list?
(a) ‘list.append(element)’ (b) ‘list.add(element)’
(c) ‘list.insert(element)’ (d) ‘list.extend(element)’
Ans.(a)
4. What is the output of ‘[1, 2, 3] + [4, 5]’?
(a) ‘[a, 2, 3, 4, 5]’ (b) ‘[1, 2, 3] [4, 5]’
(c) ‘[1, 2, 3, [4, 5]]’ (d) ‘[5, 4, 3, 2, 1]’
Ans.(a)
5. Which method removes the first occurrence of a
value from a list?
(a) ‘remove()’ (b) ‘pop()’
(c) ‘del’ (d) ‘clear()’
Ans.(a)
6. What will be the output of ‘list(range(5))’?
(a) ‘[0, 1, 2, 3, 4]’ (b) ‘[1, 2, 3, 4, 5]’
(c) ‘[0, 1, 2, 3, 4, 5]’ (d) ‘range(5)’
Ans.(a)
7. How can you access the third element of a list ‘my
list’?
(a) ‘my_list[2]’ (b) ‘my_list[3]’
(c) ‘my_list[1]’ (d) ‘my_list[–1]’
Ans.(a)
8. Which function returns the number of elements in a
list?
(a) ‘size()’ (b) ‘count()’
(c) ‘len()’ (d) ‘length()’
Ans.(c)
9. What does ‘my_list[1:4]’ return for ‘my_list = [10, 20,
30, 40, 50]’?
(a) ‘[10, 20, 30, 40]’ (b) ‘[20, 30, 40]’
(c) ‘[20, 30, 40, 50]’ (d) ‘[30, 40, 50]’
Ans.(b)
10. Which method returns and removes the last element
of a list?
(a) ‘remove()’ (b) ‘pop()’
(c) ‘del’ (d) ‘clear()’
Ans.(b)
11. How can you create a shallow copy of a list ‘my_list’?
Venus Python Programming 12
(a) ‘my_list.copy()’ (b) ‘my_list.clone()’ (a) ‘my_list.index(value)’ (b) ‘my_list.find(value)’
(c) ‘my_list[:]’ (d) Both a and c (c) ‘my_list.locate(value)’
Ans.(d) (d) ‘my_list.search(value)’
12. What is the output of ‘my_list[–1]’ for ‘my_list = [1, Ans.(a)
2, 3, 4, 5]’ ? 23. Which method would you use to combine elements
(a) 1 (b) 5 (c) 4 (d) 3 from two lists into pairs?
Ans.(b) (a) ‘zip()’ (b) ‘enumerate()’
13. Which method adds multiple elements to the end of (c) ‘map()’ (d) ‘filter()’
a list? Ans.(a)
(a) ‘append()’ (b) ‘extend()’ 24. What will be the output of ‘list(map(lambda x:x*2,
(c) ‘insert()’ (d) ‘add()’ [1, 2, 3]))’?
Ans.(b) (a) ‘[2, 4, 6]’ (b) ‘[1, 4, 9]’
14. How can you reverse the elements of a list ‘my_list’? (c) ‘[1, 2, 3, 2, 4, 6]’ (d) ‘[2, 3, 4]’
(a) ‘my_list.reverse()’ (b) ‘reversed(my_list)’ Ans.(a)
(c) ‘my_list[::–1]’ (d) All of the above 25. What will be the output of ‘my_list[::–1]’ for ‘my_list
Ans.(d) = [10, 20, 30]’?
15. What will be the output of ‘my_list[::2]’ for ‘my_list (a) ‘[30, 20, 10]’ (b) ‘[10, 20, 30]’
= [1, 2, 3, 4, 5, 6]’? (c) ‘[30, 10, 20]’ (d) ‘Error’
(a) ‘[1, 3, 5]’ (b) ‘[2, 4, 6]’ Ans.(a)
(c) ‘[1, 4, 6]’ (d) ‘[3, 5, 7]’ 26. How can you count the number of occurrences of a
Ans.(a) value in a list?
16. Which function can be used to sort a list in place? (a) ‘my_list.count(value)’ (b) ‘my_list.index(value)’
(a) ‘sort()’ (b) ‘sorted()’ (c) ‘my_list.count_elements(value)’
(c) ‘order()’ (d) ‘arrange()’ (d) ‘my_list.element_count(value)’
Ans.(a) Ans.(a)
17. How can you remove all elements from a list? 27. Which of the following is tr ue about list
(a) ‘my_list.clear()’ (b) ‘my_list.delete()’ comprehensions?
(c) ‘my_list.remove_all()’ (d) ‘my_list[:] = []’ (a) They are less readable than loops
Ans.(a) (b) They can include conditions
18. What will be the result of ‘my_list = [1, 2, 3] * 2’? (c) They cannot be nested
(a) ‘[1, 2, 3, 1, 2, 3]’ (b) ‘[1, 2, 3, 2, 4, 6]’ (d) They are always slower than loops
(c) ‘[2, 4, 6]’ (d) ‘[1, 1, 2, 2, 3, 3]’ Ans.(b)
Ans.(a) 28. What will be the output of ‘my_list[1:4:2]’ for ‘my_list
19. Which of the following is not a valid way to iterate = [1, 2, 3, 4, 5]’?
over a list in Python? (a) ‘[2, 4]’ (b) ‘[2, 3]’
(a) ‘for item in my_list’ (c) ‘[1, 3]’ (d) ‘[2, 5]’
(b) ‘for i in range(len(my_list))’ Ans.(a)
(c) ‘while item in my_list’ 29. Which function can be used to get a list of tuples
(d) ‘for index, item in enumerate(my_list)’ containing index and value pairs?
Ans.(c) (a) ‘enumerate()’ (b) ‘zip()’
20. How can you access a sublist from index 2 to 4 in (c) ‘map()’ (d) ‘filter()’
‘my_list = [10, 20, 30, 40, 50, 60]’? Ans.(a)
(a) ‘my_list[2:5]’ (b) ‘my_list[2:4]’ 30. How can you add all elements from one list to
(c) ‘my_list[1:5]’ (d) ‘my_list[3:]’ another at a specific position?
Ans.(a) (a) ‘my_list.extend(other_list)’
21. What will be the output of ‘list(filter(lambda x:x%2 (b) ‘my_list.insert(index, other_list)’
= = 0, [1, 2, 3, 4, 5]))? (c) ‘my_list[index:index] = other_list’
(a) ‘[2, 4]’ (b) ‘[1, 3, 5]’ (c) ‘my_list.append(other_list)’
(c) ‘[2, 4, 6]’ (d) ‘[1, 2, 3, 4, 5]’ Ans.(c)
Ans.(a)
22. How can you get the index of the first occurrence of
a value in a list?
Venus Python Programming 13
Chapter 8 10. How can you convert a string to uppercase in
Python?
(a) str.upper() (b) str.toUpperCase()
Arrays and Strings
(c) str.Upper() (d) str.toUpper()
Ans.(a)
Multiple ChoiCe Question 11. What is the output of the following code:
1. Which of the following correctly initializes an array print(“Hello” + “World”)?
of integers in Python? (a) Hello (b) World
(a) arr = array(1, 2, 3, 4) (b) arr = [1, 2, 3, 4] (c) HelloWorld (d) Hello World
(c) arr = {1, 2, 3, 4} (d) arr = (1, 2, 3, 4) Ans.(c)
Ans.(b) 12. Which function is used to check if a string starts
2. What is the index of the first element in an array? with a specific substring?
(a) 1 (b) –1 (a) startswith() (b) beginswith()
(c) 0 (c) start() (d) begin()
(d) It depends on the programming language Ans.(a)
Ans.(c) 13. What is the result of arr = [1, 2, 3]; arr[1] = 4;
3. Which method would you use to add an element to print(arr)?
the end of an array in Python? (a) [1, 2, 3] (b) [4, 2, 3]
(a) append() (b) add() (c) [1, 4, 3] (d) [1, 2, 4]
(c) insert() (d) push() Ans.(c)
Ans.(a) 14. Which method can be used to find the position of a
4. How do you access the third element of an array substring within a string?
named arr in Python? (a) locate() (b) position()
(a) arr[2] (b) arr[3] (c) find() (d) indexof()
(c) arr(2) (d) arr(3) Ans.(c)
Ans.(a) 15. What is the output of print(“Hello”.lower())?
5. Which of the following is not a valid way to create a (a) Hello (b) hello
string in Python? (c) Hello (d) hellO
(a) str1 = “Hello” (b) str2 = ‘Hello’ Ans.(b)
(c) str3 = “““Hello””” (d) str4 = Hello 16. How do you remove an element from a list at a
Ans.(d) specific index in Python?
6. How can you find the length of a string s in Python? (a) remove() (b) delete()
(a) length(s) (b) s.length() (c) pop() (d) discard()
(c) len(s) (d) size(s) Ans.(c)
Ans.(c) 17. Which of the following is used to reverse a list in
7. What does the method split() do in Python? Python?
(a) Splits the string into a list of substrings based on a (a) reverse() (b) flip()
delimiter (c) invert() (d) backward()
(b) Joins a list of strings into a single string Ans.(a)
(c) Replaces a substring with another substring 18. What is the purpose of the join() method in Python
(d) Converts the string to uppercase strings?
Ans.(a) (a) To concatenate elements of a list into a single string
8. How do you concatenate two strings s1 and s2 in (b) To split a string into a list of substrings
Python? (c) To replace a substring with another substring
(a) s1.concat(s2) (b) s1 + s2 (d) To find the length of a string
(c) s1 & s2 (d) s1 * s2 Ans.(a)
Ans.(b) 19. How do you check if an element exists in a list in
9. Which of the following methods removes whitespace Python?
from the beginning and end of a string in Python? (a) in keyword (b) exists() method
(a) strip() (b) remove() (c) contains() method (d) has() method
(c) trim() (d) cut() Ans.(a)
Ans.(a) 20. Which method is used to convert a list of characters
Venus Python Programming 14
into a single string? Chapter 9
(a) concat() (b) combine()
(c) join() (d) merge()
Functions
Ans.(c)
21. How do you create an empty list in Python?
(a) list() (b) [] Multiple ChoiCe Question
(c) {} (d) Both a and b 1. What is a function in programming?
Ans.(d) (a) A data structure that stores values
22. Which of the following methods can be used to sort (b) A block of code designed to perform a particular
a list in Python? task
(a) sort() (b) order() (c) A method for organizing data
(c) arrange() (d) sequence() (d) An error-handling mechanism
Ans.(a) Ans.(b)
23. What does the isalpha() method do in Python? 2. Why do we need functions in programming?
(a) Checks if all characters in the string are alphabets (a) To increase code readability
(b) Checks if the string contains only digits (b) To avoid code duplication
(c) Checks if the string contains only whitespace (c) To make maintenance easier
(d) Checks if the string contains both alphabets and digits (d) All of the above
Ans.(a) Ans.(d)
24. What will be the result of the following code : 3. Which keyword is used to define a function in
arr = [1, 2, 3]; print(arr[–1]) Python?
(a) 1 (b) 2 (c) 3 (d) Error (a) func (b) def
Ans.(c) (c) function (d) lambda
25. Which method would you use to convert a string into Ans.(b)
a list of words in Python? 4. What is a return statement used for in a function?
(a) split() (b) join() (a) To exit a loop
(c) partition() (d) divide() (b) To end a function and optionally return a value
Ans.(a) (c) To pass arguments to a function
26. How do you access the last element of an array arr (d) To call another function
in Python? Ans.(b)
(a) arr[last] (b) arr[–1] 5. What is the default return value of a function that
(c) arr[length(arr)–1] (d) arr[end] does not explicity return a value?
Ans.(b) (a) 0 (b) None
27. Which built-in function would you use to find the (c) False (d) An empty string
maximum value in a list? Ans.(b)
(a) max() (b) maximum() 6. What are function arguments?
(c) highest() (d) top() (a) Values that a function returns
Ans.(a) (b) Variables declared inside a function
28. What is the output of print(“Python”[::–1])? (c) Values passed to a function when it is called
(a) Python (b) nohtyp (d) Statements inside a function
(c) Pytho (d) Error Ans.(c)
Ans.(b) 7. What are the different types of function arguments
29. How do you create a new list by adding elements of in Python?
two lists in Python? (a) Positional, keyword, default and variable-length
(a) list1 + list2 (b) list1.append(list2) (b) Required, optional, static and dynamic
(c) list1.extendlist2) (d) list1.add(list2) (c) Global, variable, static and dynamic
Ans.(a) (d) Constant, variable, static and dynamic
30. Which of the following is used to check if a string Ans.(a)
contains only numeric characters? 8. What does the ‘yield’ keyword do in Python?
(a) isnumeric() (b)isdigit() (a) Ends a function and returns a value
(c) isdecimal() (d) isdigit() and isdecimal() (b) Returns a generator object
Ans.(d) (c) Pauses a function and returns a value
Venus Python Programming 15
(d) Creates a lambda function 17. How do you call a function named ‘my_function’ in
Ans.(c) Python?
9. Which of the following is an anonymous function in (a) call my_function() (b) exec my_function()
Python? (c) my_function() (d) execute my_function()
(a) def function(): (b) lambda x : x + 1 Ans.(c)
(c) def lambda() : (d) yield x + 1 18. What does the ‘global’ keyword do in Python?
Ans.(b) (a) Defines a global variable
10. What is recursion in programming? (b) Declares a variable as global within a function
(a) A function that calls itself (c) Imports a global library
(b) A loop inside a function (d) Calls a global function
(c) A function that calls another function Ans.(b)
(d) A way to iterate through a list 19. Which of the following is an example of a higher-
Ans.(a) order function?
11. What is the scope of a variable? (a) A function that returns a string
(a) The type of a variable (b) A function that takes another function as an
(b) The portion of the code where a variable is argument
accessible (c) A function that prints a value
(c) The value of a variable (d) A function that modifies a global variable
(d) The memory location of a variable Ans.(b)
Ans.(b) 20. What is the difference between ‘return’ and ‘yield’ in
12. What is the purpose of the ‘None’ keyword in Python?
Python? (a) ‘return’ ends a function, while ‘yield’ continues it
(a) To define a function (b) ‘return’ creates a generator, while ‘yield’ does not
(b) To return a value from a function (c) ‘return’ can return multiple values, while ‘yield’
(c) To represent the absence of a value returns only one
(d) To import a module (d) ‘return’ ends a function and returns a value, while
Ans.(c) ‘yield’ pauses the function and returns a value
13. What is a keyword argument? Ans.(d)
(a) An argument passed to a function with a specific 21. What is a function’s local scope?
name (a) The area where a function is defined
(b) An argument passed to a function without a value (b) The area where a function can be called
(c) An argument passed to a function as a default value (c) The area within a function where variables are
(d) An argument that defines the type of a function accessible
Ans.(a) (d) The area outside a function where variable are
14. Which function in Python is used to get the length accessible
of a string, list or other iterable? Ans.(c)
(a) length() (b) count() 22. Which of the following is a characteristic of an
(c) size() (d) len() anonymous function in Python?
Ans.(d) (a) Defined using the ‘def’ keyword
15. How can you define a function with default (b) Can have a name
arguments in Python? (c) Defined using the ‘lambda’ keyword
(a) def func(a = 1, b = 2) : (d) Cannot take arguments
(b) def func(a, b:1 = 1, 2 = 2) : Ans.(c)
(c) def func(1 = a, 2 = b) : 23. What does the ‘return’ keyword do in a funtion?
(d) def func(a = = 1, b = = 2) : (a) Continues the function execution
Ans.(a) (b) Terminates the function execution and optionally
16. What is a variable-length argument in Python? returns a value
(a) An argument that takes multiple values (c) Declares a local variable
(b) An argument with an unknown length (d) Defines a function
(c) An argument defined with an asterisk (*) Ans.(b)
(d) An argument passed by reference 24. How do you define a recursive function in Python?
Ans.(c) (a) By calling itself within its definition
Venus Python Programming 16
(b) By defining a function inside another function Chapter 10
(c) By using the ‘global’ keyword
(d) By using the ‘return’ keyword
Modules and Packages
Ans.(a)
25. What is a lambda function?
(a) A function defined with the ‘def’ keyword Multiple ChoiCe Question
(b) A function that has no parameters 1. Why are modules used in Python?
(c) A small anonymous function defined with ‘lambda’ (a) To organize code (b) To execute code faster
keyword (c) To increase memory usage
(d) A function that can return multiple values (d) To create graphical interfaces
Ans.(c) Ans.(a)
26. Which keyword is used to return a generator object 2. How do you create a module in Python?
in Python? (a) By creating a new folder
(a) return (b) yield (b) By writing code in a .txt file
(c) lambda (d) def (c) By writing code in a .py file
Ans.(b) (d) By writing code in a .md file
27. What does the ‘None’ keyword represent in Python? Ans.(c)
(a) A string with no value (b) A boolean value 3. What is the keyword to import a module in Python?
(c) The absence of a value (d) A zero value (a) load (b) include
Ans.(c) (c) require (d) import
28. What is an argument in the context of functions? Ans.(d)
(a) A value passed to a function when it is defined 4. What is a module namespace?
(b) A value passed to a function when it is called (a) A space where functions are stored
(c) A function that takes no parameters (b) A directory where modules are saved
(d) A function that returns no value (c) A container that holds the names defined by a
Ans.(b) module
29. What is the main advantage of using functions in (d) A keyword in Python
programming? Ans.(c)
(a) Reducing code complexity 5. How do you access a function named my_function
(b) Increasing execution speed from a module named my_module?
(c) Minimizing memory usage (a) my_module.my_function()
(d) Simplifying code comments (b) my_function.my_module()
Ans.(a) (c) my_module::my_function()
30. What is the purpose of the ‘return’ statement in a (d) my_function::my_module()
function? Ans.(a)
(a) To define a new function 6. Which of the following is true about importing
(b) To pass a value to a function modules?
(c) To terminate a function and optionally return a value (a) Modules can only be imported once
(d) To iterate through a loop (b) Modules can be imported multiple times
Ans.(c) (c) Modules cannot be imported from other packages
(d) Modules must be imported at the end of the file
Ans.(b)
7. What does the from keyword do in module import?
(a) Imports a module partially
(b) Imports a module fully
(c) Imports specific attributes from a module
(d) Prevents a module from being imported
Ans.(c)
8. What is the correct syntax to import the math
module in Python?
(a) import math_module (b) load math
(c) import math (d) include math
Venus Python Programming 17
Ans.(c) Ans.(a)
9. What does dir() function do when used with a 17. What is a module’s namespace?
module? (a) The location where the module is stored
(a) Lists all the files in a directory (b) A mapping of names to objects
(b) Lists all the functions and variables defined in the (c) The name of the module’s author
module (d) The version number of the module
(c) Deletes the module Ans.(b)
(d) Runs the module 18. How do you set the path for a package in Python?
Ans.(b) (a) By using the sys.path variable
10. How can you reload a module in Python? (b) By using the pathlib module
(a) Using import module_name again (c) By using the os.path module
(b) Using reload(module_name) from the importlib (d) By using the setpath module
library Ans.(a)
(c) Using load(module_name) again 19. What does the importlib module provide?
(d) Using include module_name again (a) Tools for importing and managing modules
Ans.(b) (b) Functions for mathematical operations
11. What is a package in Python? (c) Tools for web development
(a) A collection of variables (d) Functions for graphical interfaces
(b) A collection of modules Ans.(a)
(c) A collection of data 20. What is the main advantage of using packages in
(d) A collection of classes Python?
Ans.(b) (a) Improved performance
12. What file is required to initialize a package in (b) Better code organization
Python? (c) Easier debugging
(a) start.py (b) begin.py (d) Reduced memory usage
(c) main.py (d) init.py Ans.(b)
Ans.(d) 21. Which module is used for mathematical operations
13. How do you import a submodule from a package in in Python?
Python? (a) math (b) random
(a) import package.module (b) load package.module (c) os (d) sys
(c) include package.module Ans.(a)
(d) import module.package 22. How do you generate a random number between 1
Ans.(a) and 10 using the random module?
14. What is the purpose of the _init_.py file in a (a) random.random(1, 10) (b) random.randint(1, 10)
package? (c) random.range(1, 10) (d) random.int(1, 10)
(a) It makes Python treat the directory as a package Ans.(b)
(b) it holds the main code of the package 23. What does the math.sqrt() function do?
(c) It contains the configuration settings for the (a) Finds the square of a number
package (b) Finds the square root of a number
(d) It documents the package (c) Finds the cube of a number
Ans.(a) (d) Finds the cube root of a number
15. What is the correct syntax to import all modules from Ans.(b)
a package? 24. What is the purpose of the random.choice()
(a) from package import* function?
(b) from package import all (a) To generate a random number
(c) import package.all (b) To select a random element from a list
(d) include package* (c) To shuffle a list
Ans.(a) (d) To sort a list
16. Which of the following is a commonly used Python Ans.(b)
package for scientific computing? 25. Which module would you use to work with emojis in
(a) numpy (b) django Python?
(c) flask (d) kivy (a) math (b) random
Venus Python Programming 18
(c) emoji (d) os Chapter 11
Ans.(c)
Numpy and Pandas
Multiple ChoiCe Question
1. What is NumPy mainly used for in Python?
(a) String operations (b) Data visualization
(c) Numerical and scientific computations
(d) Web development
Ans.(c)
2. Which function is used to create a NumPy array?
(a) array() (b) create()
(c) newArray() (d) ndarray()
Ans.(a)
3. How can you create an array with all zeros in Numpy?
(a) np.zeros_array() (b) np.zeros()
(c) np.array_zeros() (d) np.create_zeros()
Ans.(b)
4. Which NumPy function is used for element-wise
addition of two arrays?
(a) add_arrays() (b) np.add()
(c) np.sum() (d) array_add()
Ans.(b)
5. Which function is used to calculate the mean of an
array in NumPy?
(a) np.average() (b) np.mean()
(c) np.median() (d) np.mode()
Ans.(b)
6. What does the reshape() function do in NumPy?
(a) Changes the shape of an array
(b) Flattens the array
(c) Removes elements from the array
(d) Adds elements to the array
Ans.(a)
7. Which of the following functions is used to
concatenate two arrays in NumPy?
(a) np.concatenate() (b) np.join()
(c) np.add() (d) np.append()
Ans.(a)
8. Which function would you use to find the standard
deviation of a NumPy array?
(a) np.std() (b) np.var()
(c) np.mean() (d) np.median()
Ans.(a)
9. What does the flatten() method do in NumPy?
(a) Converts a multi-dimensional array into a one-
dimensional array
(b) Sorts the array
(c) Rotates the array
(d) Inverts the array
Ans.(a)
Venus Python Programming 19
10. Which function is used to calculate the cumulative (c) df.group_data() (d) df.grouped()
sum of elements in a NumPy array? Ans.(b)
(a) np.sum_cumulative() (b) np.cumsum() 20. How do you add a new column to a DataFrame?
(c) np.sum() (d) np.add_cumulative() (a) df.new_column() (b) df.add_column()
Ans.(b) (c) df[‘new_column’] = values
11. What is Pandas mainly used for in Python? (d) df.insert_column(‘new_column’, values)
(a) Web development Ans.(c)
(b) Data analysis and manipulation 21. What is the key difference between a NumPy array
(c) Game development and a Pandas DataFrame?
(d) Networking (a) NumPy arrays are for string data, DataFrames are
Ans.(b) for numerical data
12. What is a Series in Pandas? (b) NumPy arrays are multi-dimensional, DataFrames
(a) A one-dimensional labeled array are two-dimensional
(b) A two-dimensional labeled array (c) NumPy arrays are immutable, DataFrames are
(c) A multi-dimensional labeled array mutable
(d) A special function in Pandas (d) NumPy arrays are not labeled, DataFrames are
Ans.(a) labeled
13. How do you create a DataFrame from a dictionary Ans.(d)
in Pandas? 22. Which function converts a NumPy array to a
(a) pd.DataFrame(dictionary) Pandas DataFrame?
(b) pd.createDataFrame(dictionary) (a) pd.DataFrame() (b) pd.convert()
(c) pd.DataFrame.from_dict(dictionary) (c) np.to_df() (d) pd.from_numpy()
(d) pd.dict_to_DataFrame(dictionary) Ans.(a)
Ans.(a) 23. How can you calculate the mean of each column in
14. Which method is used to read a CSV file into a a Pandas DataFrame?
DataFrame in Pandas? (a) df.mean(axis=0) (b) df.mean(axis=1)
(a) pd.read_csv() (b) pd.read_file() (c) df.column_mean() (d) df.mean_all()
(c) pd.load_csv() (d) pd.load_file() Ans.(a)
Ans.(a)
15. How can you display the first few rows of a
DataFrame?
(a) df.start() (b) df.head()
(c) df.begin() (d) df.show()
Ans.(b)
16. Which function is used to remove missing values
from a DataFrame?
(a) df.remove_na() (b) df.dropna()
(c) df.clean() (d) df.dropna_values()
Ans.(b)
17. How do you sort a DataFrame by a specific column?
(a) df.sort(column) (b) df.order_by(column)
(c) df.sort_values(by = column)
(d) df.order(column)
Ans.(c)
18. What does the df.info() method do?
(a) Provides a summary of the DataFrame
(b) Prints the DataFrame
(c) Shows the first few rows of the DataFrame
(d) Displays statistical information about the DataFrame
Ans.(a)
19. Which method is used to group data in a DataFrame?
(a) df.group() (b) df.groupby()
Venus Python Programming 20
Chapter 12 the file
(d) Deletes ‘Hello, World!’ from ‘example.txt’
Ans.(c)
9. Which method is used to read the entire content of a
Concept and Features of Files file into a string in Python?
(a) read() (b) readline()
Multiple ChoiCe Question (c) readlines() (d) readall()
1. What is a file in computing? Ans.(a)
(a) A type of software program 10. What does the following code do?
(b) A collection of data stored in one unit, identified by python
a filename with open(‘example.txt’, ‘r’) as file:
(c) A part of the computer’s hardware content = file.read()
(d) A type of virus print(content)
Ans.(b) (a) Writes content to ‘example.txt’
2. Which of the following is NOT a common file (b) Appends content to ‘example.txt’
operation? (c) Reads content from ‘example.txt’ and prints it
(a) Reading from a file (b) Writing to a file (d) Deletes content from ‘example.txt’
(c) Compressing a file (d) Deleting a file Ans.(c)
Ans.(c) 11. Which method is used to close a file in Python?
3. What is the primary purpose of file extensions? (a) stop() (b) close()
(a) To make files look more attractive (c) end() (d) quit()
(b) To increase the size of the file Ans.(b)
(c) To help the operating system identify the type of file 12. What is the purpose of the ‘seek()’ method in file
(d) To protect the file from viruses handling?
Ans.(c) (a) To search for a specific string in a file
4. Which function is commonly used to open a file in (b) To move the file pointer to a specific position
Python? (c) To close the file
(a) open() (b) read() (d) To delete the file
(c) write() (d) close() Ans.(b)
Ans.(a) 13. Which library in Python is commonly used for
5. Which mode is used to open a file for writing in working with data in DataFrames?
Python? (a) numpy (b) pandas
(a) ‘r’ (b) ‘w’ (c) ‘a’ (d) ‘b’ (c) matplotlib (d) scipy
Ans.(b) Ans.(b)
6. What happens when you open a file in ‘a’ mode? 14. How do you read a CSV file into a DataFrame using
(a) The file is read-only pandas?
(b) The file is written from the beginning (a) pandas.read_txt() (b) pandas.read_json()
(c) Data is appended to the end of the file (c) pandas.read_csv() (d) pandas.read_html()
(d) The file is opened in binary mode Ans.(c)
Ans.(c) 15. What does the following code do?
7. Which method is used to write data to a file in python
Python? import pandas as pd
(a) read() (b) write() df = pd.read_csv(‘data.csv’)
(c) open() (d) append() (a) Writes data to ‘data.csv’
Ans.(b) (b) Reads data from ‘data.csv’ into a DataFrame
8. What does the following code do? (c) Appends data to ‘data.csv’
python (d) Deletes data from ‘data.csv’
with open(‘example.txt’, ‘w’) as file: Ans.(b)
file.write(‘Hello, World!’) 16. Which method is used to write a DataFrame to a CSV
(a) Appends ‘Hello, World!’ to ‘example.txt’ file in Pandas?
(b) Reads ‘Hello, World!’ from ‘example.txt’ (a) to_csv() (b) write_csv()
(c) Writes ‘Hello, World!’ to ‘example.txt’ and closes (c) save_csv() (d) export_csv()
Venus Python Programming 21
Ans.(a) Chapter 13
17. What does the following code do?
python
df.to_csv(‘output.csv’, index=False)
(a) Reads data from ‘output.csv’ into a DataFrame Error and Exception Handling
(b) Writes the DataFrame ‘df’ to ‘output.csv’ without
the index Multiple ChoiCe Question
(c) Appends the DataFrame ‘df’ to ‘output.csv’ 1. What is an exception in Python?
(d) Deletes data from ‘output.csv’ (a) A syntax error
Ans.(b) (b) A runtime error that can be caught and handled
18. How do you read an Excel file into a DataFrame (c) A logical error
using pandas? (d) A type of function
(a) pandas.read_excel() (b) pandas.read_xlsx() Ans.(b)
(c) pandas.read_xls() (d) pandas.read_sheet() 2. Which of the following is not a built-in exception in
Ans.(a) Python?
19. What does the following code do? (a) ValueError (b) TypeError
python (c) CustomError (d) KeyError
df = pd.read_excel(‘data.xlsx’, sheet_name= Ans.(c)
‘Sheet1’) 3. How do you catch exceptions in Python?
(a) Writes data to ‘data.xlsx’ in ‘Sheet1’ (a) Using try and except blocks
(b) Reads data from ‘Sheet1’ of ‘data.xlsx’ into a (b) Using catch and finally blocks
DataFrame (c) Using try and catch blocks
(c) Appends data to ‘data.xlsx’ in ‘Sheet1’ (d) Using except and finally blocks
(d) Deletes data from ‘Sheet1’ of ‘data.xlsx’ Ans.(a)
Ans.(b) 4. What will happen if an exception is not caught in
Python?
(a) The program will continue running
(b) The program will terminate and print a traceback
(c) The program will handle it automatically
(d) The exception will be ignored
Ans.(b)
5. Which exception is raised when a division by zero
occurs?
(a) ValueError (b) ZeroDivisionError
(c) TypeError (d) KeyError
Ans.(b)
6. What keyword is used to define a custom exception
in Python?
(a) exception (b) raise
(c) class (d) error
Ans.(c)
7. How do you raise an exception in Python?
(a) Using the raise keyword
(b) Using the throw keyword
(c) Using the except keyword
(d) Using the catch keyword
Ans.(a)
8. Which exception is raised when an invalid index is
used in a list?
(a) KeyError (b) IndexError
(c) TypeError (d) ValueError
Ans.(b)
Venus Python Programming 22
9. Which block is executed regardless of whether an (c) It propagates to the caller
exception occurs or not? (d) It stops the execution of the program
(a) try (b) except Ans.(c)
(c) else (d) finally 18. Which exception is raised when attempting to
Ans.(d) access an undefined variable?
10. Which built-in exception is raised when a key is not (a) NameError (b) KeyError
found in a dictionary? (c) ValueError (d) TypeError
(a) ValueError (b) KeyError Ans.(a)
(c) IndexError (d) TypeError 19. How can you re-raise an exception in Python?
Ans.(b) (a) Using the raise keyword
11. What is the output of the following code? (b) Using the except keyword
python (c) Using the finally keyword
Copy code (d) Using the try keyword
(a) Division by zero! This is always executed Ans.(a)
(b) This is always executed. Division by zero! 20. What is the output of the following code?
(c) Division by zero! python
(d) Error Copy code
Ans.(a) (a) MyError: An error occurred
12. Which exception is raised for an invalid operation (b) An error occurred
on a data type? (c) MyError
(a) TypeError (b) ValueError (d) Error
(c) KeyError (d) IndexError Ans.(b)
Ans.(a) Dear Students,
13. How can you create a user-defined exception?
(a) By inheriting from the Exception class
Venus Publication Question Bank are avail-
(b) By using the raise keyword able at your nearest book store.
(c) By using the class keyword All Question are important and taken from
(d) By inheriting from the BaseException class MSBTE, JUT and Bihar SBTE.
Ans.(a) For any query or problem , Please whatapps
14. What will the following code output?
python on +91 9007069442.
Copy code
(a) A ValueError occurred (b) hello
(c) Error (d) None
Ans.(a)
15. What is the purpose of the else block in exception
handling?
(a) It executes if an exception occurs
(b) It executes if no exception occurs
(c) It handles all exceptions
(d) It is used for cleanup actions
Ans.(b)
16. Which exception is raised when an operation or
function receives an argument with the right type
but an inappropriate value?
(a) TypeError (b) ValueError
(c) KeyError (d) IndexError
Ans.(b)
17. What happens if an exception occurs in the finally
block?
(a) It is ignored
(b) It is caught by the except block