General Python VI
1.
How do you remove the last element from a list in Python?
list.remove_last()
del list[-1]
list.delete_last()
list.prop()
2.
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
3.
How can you check if a variable is a string in Python?
type(variable) == str
variable.is_string()
isinstance(variable, string)
variable.type() == "string"
4.
What is the output of the following code?
print(10 // 3)
3.33
3
3.0
Error
5.
How do you convert a list of integers to a list of strings in Python?
str(list)
[str(x) for x in list]
list.to_strings()
convert_to_strings(list)
6.
What is the purpose of the `sys.argv` list in Python?
To store command-line arguments
To access system environment variables
To store function arguments
To define script arguments
7.
How do you concatenate two strings in Python?
string.join(string2)
string.concat(string2)
string + string2
concat(string, string2)
8.
What is the purpose of the `os.mkdir` function in Python?
To make a new file
To create a new directory
To remove a directory
To rename a file
9.
How do you check if a variable is a boolean in Python?
variable.is_boolean()
type(variable) == bool
isinstance(variable, boolean)
variable.type() == "boolean"
10.
What is the purpose of the `os.path.abspath` function in Python?
To get the absolute path of a file
To check if a file exists
To create a new path
To join two paths together
11.
What does the `__doc__` attribute represent in Python?
The current module's documentation
The class's documentation
The function's documentation
The object's documentation string
12.
What is the purpose of the `os.path.isfile` function in Python?
To check if a file is readable
To check if a file exists
To check if a file is a directory
To check if a file is writable
13.
How do you remove all occurrences of a specific element from a list in Python?
list.remove_all(element)
list = [x for x in list if x != element]
list.delete(element)
list.remove(element)
14.
What is the purpose of the `sorted()` function in Python?
To sort elements in a list in ascending order
To reverse the order of elements in a list
To shuffle elements in a list
To perform a quicksort algorithm
15.
What is the output of the following code?
print("Python" * 2)
PythonPython
Python2
Python * 2
Error
16.
What is the purpose of the `os.path.splitext` function in Python?
To split a path into its base and extension
To create a new path
To join two paths together
To check if a file exists
17.
What is the output of the following code?
print(2 * 3 ** 3)
18
24
162
54
18.
How can you iterate over the values of a dictionary in Python?
for value in dict:
for value in dict.values():
for value in dict.items():
for value in dict.keys():
19.
What is the correct way to open a file for both reading and writing in Python?
open("file.txt", "rw")
open("file.txt", "r+")
open("file.txt", "w+")
open("file.txt", "a+")
20.
What is the output of the following code?
print("Python"[1:-1])
P
Python
Pyt
ytho