General Python X
1.
How do you check if a number is even in Python?
number.is_even()
number % 2 == 0
is_even(number)
number.even()
2.
What is the output of the following code?
print(7 % 3)
1
2
3
Error
3.
What is the output of the following code?
print("Python"[-3:])
Pth
Pyt
Pon
hon
4.
What is the output of the following code?
print("Python".find("th"))
1
2
3
Error
5.
What is the output of the following code?
print(len("Python"))
5
6
7
Error
6.
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
7.
What is the output of the following code?
print(3 + 4 * 2)
14
17
24
Error
8.
How can you check if a file exists in Python?
os.file_exists("filename")
file.exists()
os.path.exists("filename")
file.is_existing()
9.
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]
10.
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
11.
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()
12.
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)
13.
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
14.
How do you check if a variable is an integer in Python?
variable.is_integer()
type(variable) == int
isinstance(variable, int)
variable.type() == "integer"
15.
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
16.
How do you check if a string is a palindrome in Python?
string.is_palindrome()
string == string.reverse()
string == string[::-1]
check_palindrome(string)
17.
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
18.
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"]
19.
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
20.
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, " ")