General Python V
1.
What is the purpose of the `functools` module in Python?
To create functions
To manipulate functions
To perform mathematical operations
To optimize function calls
2.
How do you round a floating-point number to the nearest integer in Python?
round(num)
int(num)
math.round(num)
{:.0f}.format(num)
3.
What is the purpose of the `itertools` module in Python?
To create iterators
To perform iterative operations
To manipulate strings iteratively
To optimize iterations
4.
How can you check if a string contains a specific substring in Python?
substring.in_string(string)
string.has_substring(substring)
substring in string
check_substring(string, substring)
5.
What is the purpose of the `bisect` module in Python?
To perform binary search on lists
To bisect strings into substrings
To calculate the bisector of an angle
To manipulate binary data
6.
How do you check if a variable is a list in Python?
type(variable) == "list"
variable.is_list()
isinstance(variable, list)
variable.type() == "list"
7.
What is the correct way to create a shallow copy of a list in Python?
list.copy()
copy(list)
list.clone()
new_list = list
8.
What is the purpose of the `os.path.exists` function in Python?
To check if a file exists
To create a new file
To delete a file
To check if a directory exists
9.
How do you convert a string to a lowercase in Python?
str.to_lower()
string.lowercase()
string.to_lowercase()
string.lower()
10.
What is the output of the following code?
print("Hello" + "World")
HelloWorld
Hello World
Hello + World
Error
11.
What does the `repr()` function do in Python?
Returns the representation of an object as a string
Returns the length of a string
Returns the ASCII value of a character
Repeats a string
12.
What is the output of the following code?
print("Python" * 0)
0
Error
None
Empty String
13.
What is the output of the following code?
print("Python"[1:4])
P
ython
Pyt
yth
14.
What is the output of the following code?
print(5 / 2)
2.5
2
2.0
2.2
15.
How do you find the length of a string in Python?
length(string)
string.length()
len(string)
size(string)
16.
How do you check if a string contains only numeric characters?
string.isdigit()
numeric(string)
string.isnumeric()
is_number(string)
17.
What is the purpose of the `collections.Counter` class in Python?
To count the number of elements in a list
To create a counter for loop iterations
To count occurrences of elements in a collection
To perform mathematical operations on counters
18.
What is the purpose of the `os.path.join` function in Python?
To join paths together
To create a new path
To split a path
To check if a path exists
19.
What does the `pass` statement do in Python?
Exits the loop
Does nothing and continues to the next iteration or block of code
Skips the current iteration and moves to the next
Breaks out of the loop
20.
How do you check if a string is empty in Python?
string.isempty()
len(string) == 0
string == ""
is_empty(string)