4/3/25, 1:56 PM FlexiQuiz - Editor
FDP-ADVANCED PYTHON
Which of the following is the correct syntax for inheriting a class in Python?
a) class SubClass: super(BaseClass)
b) class SubClass(BaseClass):
c) class SubClass - BaseClass:
d) class SubClass < BaseClass:
Which module in Python supports regular expressions?
a) re
b) regex
c) pyregex
d) none of the mentioned
What is a file descriptor in an operating system?
A pointer to a file in the file system
A unique identifier for an open file within a process
A memory location where the file content is stored
A special type of file used by the OS for I/O operations
https://www.flexiquiz.com/create/edit/f85074ca-3997-4808-be41-6b6b1c2b161a 1/15
4/3/25, 1:56 PM FlexiQuiz - Editor
What is a file descriptor in an operating system?
A pointer to a file in the file system
A unique identifier for an open file within a process
A memory location where the file content is stored
A special type of file used by the OS for I/O operations
Which of the following is a correct lambda function to add two numbers?
lambda x, y: return x + y
lambda (x, y) => x + y
lambda x, y: x + y
lambda x y: x + y
Which of the following is a correct list comprehension to create a list of squares of numbers from 0
to 4?
[x**2 for x in range(5)]
[x^2 for x in range(5)]
[x**2 for x in range(1, 6)]
[x*x for x in range(5, 10)]
Which of the following is a dictionary comprehension to create a dictionary where keys are numbers
from 1 to 3 and values are their cubes?
{x: x**3 for x in range(1, 4)}
{x: x**2 for x in range(3)}
{x: x*3 for x in range(1, 4)}
{x**2: x for x in range(1, 4)}
What will be the output of the following list comprehension: [x+y for x in [1, 2] for y in [3, 4]]?
[4, 5, 5, 6]
[4, 6, 5, 7]
[4, 6, 7, 9]
[1, 2, 3, 4]
https://www.flexiquiz.com/create/edit/f85074ca-3997-4808-be41-6b6b1c2b161a 2/15
4/3/25, 1:56 PM FlexiQuiz - Editor
Which of the following is an example of a simple decorator?
def decorator(func): def wrapper(): return func() return wrapper
@decorator
def wrapper(): return func()
@wrapper
What is the output of the following code?
python
Copy code
def outer_func(x):
def inner_func(y):
return x + y
return inner_func
add_five = outer_func(5)
print(add_five(10))
A)15
B)10
C)5
D)Error
What is the output of the following list comprehension?
python
Copy code
[x for x in range(5) if x % 2 == 0]
A) [0, 1, 2, 3, 4]
B) [1, 3]
C) [0, 2, 4]
D) [2, 4]
https://www.flexiquiz.com/create/edit/f85074ca-3997-4808-be41-6b6b1c2b161a 3/15
4/3/25, 1:56 PM FlexiQuiz - Editor
What is a closure in Python?
A) A function that is passed as an argument to another function
B) A function object that remembers values in enclosing scopes even if they are not present in
memory
C) A function that returns another function as its result
D) A function that decorates another function to extend its behavior
What will be the output of the following code?
python
Copy code
def outer_func(x):
def inner_func(y):
return x + y
return inner_func
closure = outer_func(10)
print(closure(5))
15
10
Error, because x is not in the scope of inner_func
Which Python module is primarily used for interacting with the file system, including files and
directories?
sys
os
fileinput
datetime
https://www.flexiquiz.com/create/edit/f85074ca-3997-4808-be41-6b6b1c2b161a 4/15
4/3/25, 1:56 PM FlexiQuiz - Editor
Which method is used to execute a SQL command in the sqlite3 module?
a) cursor.execute()
b) connection.run()
c) cursor.run()
d) connection.execute()
Which of the following file descriptors is typically used for standard output (stdout) in Unix-like
systems?
If a process opens a file multiple times, how many different file descriptors will it have for that file?
One file descriptor shared across all opens
One file descriptor per process
A unique file descriptor for each open call
None of the above
What happens when a file descriptor is closed in a process?
The file descriptor is removed from the process’s file descriptor table
The file is deleted from the disk
The file descriptor is reused immediately for another file
The file descriptor remains valid until the process terminates
What is the purpose of the . and .. directories in Unix-like file systems?
refers to the current directory, and .. refers to the parent directory.
refers to the root directory, and .. refers to the home directory.
Both . and .. refer to hidden files in the current directory.
and .. are reserved for system use and cannot be accessed.
https://www.flexiquiz.com/create/edit/f85074ca-3997-4808-be41-6b6b1c2b161a 5/15
4/3/25, 1:56 PM FlexiQuiz - Editor
What happens when the os.remove("example.txt") command is executed in Python?
The file "example.txt" is moved to the trash or recycle bin.
The file "example.txt" is permanently deleted from the file system.
The file "example.txt" is opened in read mode.
The file "example.txt" is copied to another directory.
What is a lambda function in Python?
A named function defined with the def keyword
An anonymous function defined with the lambda keyword
A function that is executed only once
A function that returns another function
Which of the following is a correct lambda function to add two numbers?
lambda x, y: return x + y
lambda (x, y) => x + y
lambda x, y: x + y
lambda x y: x + y
What is the output of the following code: (lambda x: x * 2)(5)
10
25
20
Lambda functions are typically used for:
Defining named functions
Performing operations on data structures like lists using map, filter, and reduce
Creating classes in Python
Writing complex and multi-line functions
https://www.flexiquiz.com/create/edit/f85074ca-3997-4808-be41-6b6b1c2b161a 6/15
4/3/25, 1:56 PM FlexiQuiz - Editor
Which of the following best describes a lambda function?
A reusable, anonymous function that is defined on the fly
A function with a unique name that can be called multiple times
A function that is only used in object-oriented programming
A function that is always recursive
Which of the following is a correct list comprehension to create a list of squares of numbers from 0
to 4?
[x**2 for x in range(5)]
[x^2 for x in range(5)]
[x**2 for x in range(1, 6)]
[x*x for x in range(5, 10)]
What is the main advantage of using list comprehensions in Python?
They make code faster
They make code more readable and concise
They allow the creation of infinite lists
They replace the need for loops
Which of the following is a set comprehension to create a set of even numbers from 0 to 10?
{x for x in range(11) if x % 2 == 0}
{x for x in range(10)}
{x**2 for x in range(11) if x % 2 == 0}
{x*2 for x in range(11)}
Which of the following is a dictionary comprehension to create a dictionary where keys are numbers
from 1 to 3 and values are their cubes?
{x: x**3 for x in range(1, 4)}
{x: x**2 for x in range(3)}
{x: x*3 for x in range(1, 4)}
{x**2: x for x in range(1, 4)}
https://www.flexiquiz.com/create/edit/f85074ca-3997-4808-be41-6b6b1c2b161a 7/15
4/3/25, 1:56 PM FlexiQuiz - Editor
What will be the output of the following list comprehension: [x+y for x in [1, 2] for y in [3, 4]]?
[4, 5, 5, 6]
[4, 6, 5, 7]
[4, 6, 7, 9]
[1, 2, 3, 4]
What is a closure in Python?
A function that has its own local variables
A function that returns another function
A function that remembers the environment in which it was created
A function that can only be called once
Which of the following best describes a decorator in Python?
A function that is used to modify the behavior of another function
A function that can only be used in classes
A built-in Python function
A function that prints out a message before executing another function
Which of the following is an example of a simple decorator?
def decorator(func): def wrapper(): return func() return wrapper
@decorator
def wrapper(): return func()
@wrapper
https://www.flexiquiz.com/create/edit/f85074ca-3997-4808-be41-6b6b1c2b161a 8/15
4/3/25, 1:56 PM FlexiQuiz - Editor
What is the output of the following code?
python
Copy code
def outer_func(x):
def inner_func(y):
return x + y
return inner_func
add_five = outer_func(5)
print(add_five(10))
15
10
Error
Which of the following is an immutable data type in Python?
List
Dictionary
Tuple
Set
What is the output of the following Python code?
type(5.0)
class 'int'
class 'float'
class 'double'
class 'complex'
Which of the following data types is used to store a sequence of characters in Python?
List
String
Set
Dictionary
https://www.flexiquiz.com/create/edit/f85074ca-3997-4808-be41-6b6b1c2b161a 9/15
4/3/25, 1:56 PM FlexiQuiz - Editor
Which of the following is the correct syntax for a lambda function that adds 10 to a number?
lambda x: x + 10
lambda x, 10: x + 10
add_10 = lambda x + 10
def lambda x: x + 10
What will be the output of the following code?
f = lambda x, y: x * y
print(f(3, 4))
12
34
10
Which of the following statements about lambda functions is true?
Lambda functions can have multiple expressions.
Lambda functions are used only within filter() and map() functions.
Lambda functions can have any number of arguments but only one expression.
Lambda functions must be named.
How would you use a lambda function to sort a list of tuples by the second element?
sorted(tuples, key=lambda x: x[0])
sort(tuples, key=lambda x: x[1])
sorted(tuples, key=lambda x: x[1])
sort(tuples, key=lambda x: x[0])
What is the primary purpose of list comprehensions in Python?
To define a list with elements of different data types
To iterate over a list and modify its elements in place
To create a new list by applying an expression to each element of an existing iterable
To define a function that returns a list
https://www.flexiquiz.com/create/edit/f85074ca-3997-4808-be41-6b6b1c2b161a 10/15
4/3/25, 1:56 PM FlexiQuiz - Editor
Which of the following is a correct example of a list comprehension that squares each number in a
list numbers?
[x^2 for x in numbers]
[x*x for x in numbers]
(x**2 for x in numbers)
{x**2 for x in numbers}
How can you create a list of the lengths of each word in a list words using list comprehension?
[len(word) in words]
[for len(word) in words]
[len(word) for word in words]
[word.len() for word in words]
Which of the following is a correct example of a set comprehension that generates a set of squares
for numbers 1 through 5?
{x*x for x in range(1, 6)}
[x**2 for x in range(1, 6)]
(x**2 for x in range(1, 6))
{x for x in range(1, 6)}
What is the output of the following dictionary comprehension?
{x: x**2 for x in range(3)
{1: 0, 2: 1, 3: 4}
{0: 0, 1: 1, 2: 4}
{0: 1, 1: 2, 2: 3}
{0: 0, 1: 1, 2: 2}
What is a closure in Python?
A function that is passed as an argument to another function
A function object that remembers values in enclosing scopes even if they are not present in
memory
A function that returns another function as its result
A function that decorates another function to extend its behavior
https://www.flexiquiz.com/create/edit/f85074ca-3997-4808-be41-6b6b1c2b161a 11/15
4/3/25, 1:56 PM FlexiQuiz - Editor
What will be the output of the following code?
def outer_func(x):
def inner_func(y):
return x + y
return inner_func
closure = outer_func(10)
print(closure(5)
15
10
Error, because x is not in the scope of inner_func
What is a file descriptor in Python?
A unique identifier for a file or socket
A string representing the file path
A function used to describe a file's contents
A method to read from or write to a file
Which Python module provides functions to work directly with file descriptors?
sys
io
os
fileinput
Which function is used to remove a file in Python? (Select two right answers)
os.remove()
os.delete()
os.unlink()
os.downlink
https://www.flexiquiz.com/create/edit/f85074ca-3997-4808-be41-6b6b1c2b161a 12/15
4/3/25, 1:56 PM FlexiQuiz - Editor
How would you check if a specific file example.txt exists in the current directory? (Select two right
answers)
os.path.exists('example.txt')
os.path.isfile('example.txt')
os.file.exists('example.txt')
os.path.found('example.txt')
What is the output of the following code?
count = 0
while count < 3:
print(count)
count += 1
01
123
012
0123
Which of the following Python libraries is commonly used for data visualization in analysis?
NumPy
Pandas
Matplotlib
Flask
Which Python version introduced new-style classes?
Python 1.0
Python 2.0
Python 2.2
Python 3.0
https://www.flexiquiz.com/create/edit/f85074ca-3997-4808-be41-6b6b1c2b161a 13/15
4/3/25, 1:56 PM FlexiQuiz - Editor
Which Python module is used to define Abstract Base Classes?
abc
abstract
baseclass
object
What is SQLite?
A server-based relational database management system
A lightweight, serverless, self-contained relational database engine
A NoSQL database system
A cloud-based database service
Which method is used to execute a SQL command in the sqlite3 module?
cursor.execute()
connection.run()
cursor.run()
connection.execute()
How do you commit changes to an SQLite database after executing INSERT, UPDATE, or DELETE
commands?
cursor.commit()
connection.commit()
sqlite3.commit()
commit()
Which of the following methods is used to close the connection to an SQLite database?
conn.stop()
cursor.close()
conn.close()
sqlite3.disconnect()
https://www.flexiquiz.com/create/edit/f85074ca-3997-4808-be41-6b6b1c2b161a 14/15
4/3/25, 1:56 PM FlexiQuiz - Editor
Which of the following correctly represents the method resolution order (MRO) in Python?
class A: pass
class B(A): pass
class C(A): pass
class D(B, C): pass
D -> B -> A -> C
D -> B -> C -> A
D -> C -> B -> A
D -> A -> B -> C
https://www.flexiquiz.com/create/edit/f85074ca-3997-4808-be41-6b6b1c2b161a 15/15