
Q31
Q31 How do you import a module in Python?
using the import keyword
using the include keyword
using the require keyword
using the module keyword
Q32
Q32 What is the difference between arguments and parameters in Python functions?
No difference
Parameters define, arguments call
Arguments define, parameters call
Based on data type
Q33
Q33 What is the output of this code:
def add(x, y):
return x + y;
print(add(3, 4))
3
4
7
Error
Q34
Q34 Pseudocode:
Function that checks if a number is positive, negative, or zero
Prints type of number
Returns type of number
No output
Error
Q35
Q35 Identify the error:
def my_func(x, y):
return x + y;
my_func(1)
Missing argument
Syntax error
Logic error
No error
Q36
Q36 Find the mistake:
import math;
print(math.sqr(4))
Incorrect module
Incorrect function name
Wrong number of arguments
No error
Q37
Q37 What is the purpose of the open() function in Python?
To read data from URL
To open a new Python file
To open a file
To create a Python module
Q38
Q38 Which file mode in Python allows you to read and write to a file?
r+
w+
a+
rb+
Q39
Q39 What does the following code do?
with open('file.txt', 'w') as file:
file.write("Hello World")
Reads from file.txt
Writes "Hello World" to file.txt
Deletes file.txt
Creates a new file
Q40
Q40 What is the result of this code?
f = open('file.txt', 'r');
print(f.readline())
Prints entire file
Prints the first line of file.txt
Error
Prints 'file.txt'
Q41
Q41 Pseudocode:
Open 'data.txt', read each line, print each line
Prints name of the file
Prints contents of data.txt
Error
No output
Q42
Q42 Find the mistake:
with open('data.txt', 'r') as file:
data = file.readlines();
print(data[2])
Wrong function used
Error in print statement
Index error
No error
Q43
Q43 Identify the error in this code:
try:
x = 1 / 0
except:
print("An error occurred")
Division by zero is not handled properly
Generic exception should not be used
Syntax error in try statement
No error
Q44
Q44 Find the mistake: try:
x = 1 / "0"
except ValueError:
print("Type error occurred")
Wrong exception type is caught
Should be ZeroDivisionError
It will raise a TypeError
No error
Q45
Q45 What is the key difference between list comprehensions and generator expressions?
The syntax used
The type of brackets used
List comprehensions produce lists, while generator expressions produce generators
Execution speed
Q46
Q46 What does the following dictionary comprehension do?
{x: x*x for x in range(5)
if x%2 == 0}
Squares of all numbers from 0 to 4
Squares of odd numbers from 0 to 4
Squares of even numbers from 0 to 4
Cubes of even numbers from 0 to 4
Q47
Q47 Identify the error in this code:
[x for x in range(10)
if x%2 = 0]
Syntax error in range function
Incorrect use of assignment operator
List comprehension is incorrectly formed
No error
Q48
Q48 How is a lambda function different from a regular function defined using def in Python?
Lambda can only have one expression
Lambda can return multiple values
Lambda functions are faster
Lambda functions can't have arguments
Q49
Q49 What is the output of the following lambda expression?
(lambda x, y: x * y)(3, 4)
7
12
0
SyntaxError
Q50
Q50 How is a class attribute different from an instance attribute in Python?
Class attributes are shared by all instances
Instance attributes can't be changed
Class attributes can't be accessed by instances
No difference
Q51
Q51 Pseudocode:
Define a class 'Car'
with a method 'drive';
Create an instance of 'Car';
Call 'drive' method
Error as 'drive' method is undefined
The 'drive' method of the 'Car' instance is executed
Nothing as 'Car' has no attributes
A new 'Car' object is created
Q52
Q52 What is inheritance in object-oriented programming?
Sharing data between classes
Copying methods from one class to another
Deriving new classes from existing classes
Protecting data within a class
Q53
Q53 How does polymorphism enhance code reusability?
By allowing methods to perform different tasks based on the object
By using the same method in multiple classes
By changing the functionality of inherited methods
By encapsulating code in modules
Q54
Q54 Pseudocode:
Create a base class 'Shape', derived classes 'Circle', 'Square'; Implement method 'area' in both
Error, as 'area' cannot be implemented in 'Shape'
Circle' and 'Square' can't inherit from 'Shape'
area' method behaves differently in 'Circle' and 'Square'
'Shape' should not have an 'area' method
Q55
Q55 How do decorators contribute to cleaner code in Python?
By reducing the need for global variables
By providing a syntax for error handling
By allowing code reuse and adding functionality to existing code
By optimizing memory usage
Q56
Q56 How do generators differ from standard functions?
Generators can't take arguments
Generators don't return values
Generators yield values, maintaining state between each yield
Generators execute faster
Q57
Q57 What is the main difference between threading and multiprocessing in Python?
Threading is faster
Multiprocessing uses more memory
Threading involves parallel execution
Multiprocessing involves separate memory spaces for each process
Q58
Q58 When should you choose multiprocessing over threading in Python?
For I/O-bound tasks
For quick tasks
For CPU-bound tasks
When memory usage is a concern
Q59
Q59 Which module in Python provides support for regular expressions?
sys
re
os
json
Q60
Q60 What does the regular expression ^a...s$ match?
Any seven-letter string starting with 'a' and ending with 's'
Any string starting with 'a' and ending with 's'
Any five-letter string starting with 'a' and ending with 's'
Any string containing 'a' and 's'

