General Python VII
1.
What is the purpose of the `math.ceil()` function in Python?
To calculate the floor value of a number
To round a number to the nearest integer
To calculate the ceiling value of a number
To perform exponential calculations
2.
What is the output of the following code?
print(len("Python"))
5
6
7
Error
3.
What does the `ord()` function do in Python?
Returns the ASCII value of a character
Returns the character of an ASCII value
Counts the number of characters in a string
Converts a string to uppercase
4.
How can you check if a file is writable in Python?
os.is_writable("filename")
file.can_write()
os.access("filename", os.W_OK)
file.is_writable()
5.
How do you convert a string to a tuple in Python?
str.to_tuple()
convert_to_tuple(string)
tuple(string)
tuple(char for char in string)
6.
What is the output of the following code?
print(7 % 3)
1
2
3
Error
7.
How do you check if a variable is an integer in Python?
variable.is_integer()
type(variable) == int
isinstance(variable, integer)
variable.type() == "integer"
8.
How do you convert a list of strings to a single string with spaces between elements in Python?
.join(list)
list.combine(" ")
merge(list, " ")
.concat(list)
9.
What is the output of the following code?
print(3 + 4 * 2)
14
24
11
Error
10.
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
11.
What is the output of the following code?
print("Python"[-3:])
Pth
Pyt
Pon
hon
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 do you check if a string is a palindrome in Python?
string.is_palindrome()
string == string.reverse()
string == string[::-1]
check_palindrome(string)
14.
What is the output of the following code?
print("Python".find("th"))
3
Error
1
2
15.
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"]
16.
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
17.
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
18.
How do you check if a number is even in Python?
number.is_even()
number % 2 == 0
is_even(number)
number.even()
19.
How can you check if a file exists in Python?
os.file_exists("filename")
file.exists()
os.path.exists("filename")
file.is_existing()
20.
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]