General Python VIII
1.
How do you convert a string to a tuple in Python?
tuple(string)
str.to_tuple()
tuple(char for char in string)
convert_to_tuple(string)
2.
What is the purpose of the `os.path.isdir` function in Python?
To check if a file is readable
To check if a path is a directory
To check if a file exists
To check if a file is writable
3.
What is the purpose of the `zip()` function in Python?
To compress files
To zip folders
To create a zip file
To combine iterables element-wise
4.
What is the output of the following code?
print("Python"[-3:])
Pth
Pyt
Pon
hon
5.
What is the output of the following code?
print(len("Python"))
5
6
7
Error
6.
How do you convert a list of strings to a single string with spaces between elements in Python?
.join(list)
.join(list)
list.combine(" ")
merge(list, " ")
7.
What is the output of the following code?
print(3 + 4 * 2)
14
17
24
Error
8.
What is the output of the following code?
print(max("Python"))
P
y
t
Error
9.
How do you check if a variable is a float in Python?
variable.is_float()
type(variable) == float
isinstance(variable, float)
variable.type() == "float"
10.
What is the output of the following code?
print(7 % 3)
1
2
3
Error
11.
How do you check if a variable is an integer in Python?
variable.is_integer()
type(variable) == int
isinstance(variable, integer)
variable.type() == "integer"
12.
What is the purpose of the `shutil` module in Python?
To manipulate strings
To perform shell-like operations
To perform file operations
To create shortcuts
13.
How can you check if a variable is a list or a tuple in Python?
type(variable) == list or tuple
variable.is_list_or_tuple()
isinstance(variable, (list, tuple))
variable.type() in ["list", "tuple"]
14.
What does the `split()` method do in Python?
Splits a string into a list of substrings based on a delimiter
Joins two strings together
Removes leading and trailing whitespaces from a string
Finds the first occurrence of a substring in a string
15.
What is the purpose of the `chr()` function in Python?
Converts a character to its ASCII value
Converts an ASCII value to a character
Returns the Unicode code point of a character
Converts a string to uppercase
16.
How do you check if a number is even in Python?
number.is_even()
number % 2 == 0
is_even(number)
number.even()
17.
How can you check if a file exists in Python?
os.file_exists("filename")
file.exists()
os.path.exists("filename")
file.is_existing()
18.
How do you remove all occurrences of a specific element from a list in Python?
list.remove_all(element)
list.clear(element)
list.remove(element)
list = [x for x in list if x != element]
19.
What is the purpose of the `heapq` module in Python?
To implement heaps in Python
To sort elements in a list
To manage the heap memory
To perform mathematical operations
20.
How do you concatenate two lists in Python?
list.extend(list2)
list.concatenate(list2)
list + list2
concat(list, list2)