What does this Python code output?
print(5 // 2)
Correct answer:
A) 2
Explanation: The // operator performs floor division, which returns the largest integer less than or equal to the result.
What does this Python code output?
print(5 // 2)
Correct answer:
A) 2
Explanation: The // operator performs floor division, which returns the largest integer less than or equal to the result.
What does the following Python code output?
x = [“a”, “b”, “c”]
x.append(“d”)
print(x)
Correct answer:
B) [“a”, “b”, “c”, “d”]
Explanation: The append() method adds an element to the end of the list.
What does the following Python code return?
print(len([1, 2, 3, 4, 5]))
Correct answer:
B) 5
Explanation: The len() function returns the number of elements in the list, which is 5 in this case.
What does this Python code return?
print(“Hello, World!”.upper())
Correct answer:
B) HELLO, WORLD!
Explanation: The upper() method converts all the letters in the string to uppercase.
What will this Python code return?
x = [1, 2, 3, 4]
print(x.index(3))
Correct answer:
B) 2
Explanation: The index() method returns the index of the first occurrence of the specified value. The value 3 is at index 2 .
What does this Python code return?
print(2 ** 3)
Correct answer:
C) 8
Explanation: The ** operator is used for exponentiation. 2 ** 3 means 2 raised to the power of 3 , which equals 8 .
What will the following Python code output?
fruits = [“apple”, “banana”, “cherry”]
fruits.sort()
print(fruits)
Correct answer:
A) [“apple”, “banana”, “cherry”]
Explanation: The sort() method sorts the list in ascending alphabetical order.
What is the output of this Python code?
print(“abc” + “def”)
Correct answer:
B) abcdef
Explanation: The + operator concatenates two strings. "abc" + "def" results in "abcdef" .
What does this Python code return?
print([1, 2, 3].pop())
Correct answer:
C) 3
Explanation: The pop() method removes and returns the last item from the list. In this case, 3 is the last item.
What will this Python code output?
print(10 % 3)
Correct answer:
A) 1
Explanation: The % operator returns the remainder of the division. 10 % 3 equals 1 because 10 divided by 3 leaves a remainder of 1.
What does this Python code return?
print(“Python”.startswith(“P”))
Correct answer:
A) True
Explanation: The startswith() method checks whether a string starts with a specified prefix. "Python".startswith("P") returns True .
What is the output of this Python code?
print(list(range(3)))
Correct answer:
C) [0, 1, 2]
Explanation: The range(3) function generates a sequence of numbers starting from 0 up to but not including 3 .
What will this Python code output?
print(3 == 3.0)
Correct answer:
A) True
Explanation: In Python, 3 and 3.0 are considered equal because Python performs type coercion for numerical comparison.
What does this Python code return?
print(“123”.isdigit())
Correct answer:
A) True
Explanation: The isdigit() method returns True if all characters in the string are digits. "123" contains only digits, so it returns True .
What will this Python code output?
print(2 != 3)
Correct answer:
A) True
Explanation: The != operator checks whether two values are not equal. Since 2 is not equal to 3 , the result is True .
What does this Python code return?
print([1, 2, 3] == [1, 2, 3])
Correct answer:
A) True
Explanation: The == operator compares the values of two lists. Since both lists contain the same values in the same order, the result is True .
What will be the result of this Python code?
x = [1, 2, 3]
print(len(x))
Correct answer:
C) 3
Explanation: The len() function returns the number of elements in a list. x contains three elements, so the result is 3 .
What does this Python code output?
x = 5
y = “5”
print(str(x) == y)
Correct answer:
A) True
Explanation: The str() function converts the integer 5 to the string "5" , making the comparison True .
What does this Python code return?
x = [1, 2, 3]
y = x
y.append(4)
print(x)
Correct answer:
B) [1, 2, 3, 4]
Explanation: Both x and y refer to the same list in memory. Modifying y also affects x .
What does this Python code output?
x = [1, 2, 3]
y = x.copy()
y.append(4)
print(x)
Correct answer:
A) [1, 2, 3]
Explanation: The copy() method creates a shallow copy of the list. Modifications to y do not affect the original list x .
What does this Python code return?
print(“Python”.find(“y”))
Correct answer:
C) 2
Explanation: The find() method returns the index of the first occurrence of the specified substring. "y" occurs at index 2 in "Python" .
What will be the output of this Python code?
x = “banana”
y = “apple”
print(x > y)
Correct answer:
A) True
Explanation: String comparison is done lexicographically based on Unicode values. "banana" comes after "apple" , so the result is True .
What does this Python code return?
print([1, 2, 3, 4][:2])
Correct answer:
A) [1, 2]
Explanation: The slice [:2] returns elements from the start of the list up to but not including index 2 , which results in [1, 2] .
What will this Python code output?
x = [1, 2, 3]
x.insert(1, “a”)
print(x)
Correct answer:
B) [1, “a”, 2, 3]
Explanation: The insert() method inserts an element at a specified index. "a" is inserted at index 1 .
What does this Python code return?
x = [1, 2, 3]
x.clear()
print(x)
Correct answer:
A) []
Explanation: The clear() method removes all elements from the list, leaving it empty.
What is the result of this Python code?
x = [“apple”, “banana”]
x.extend([“cherry”, “date”])
print(x)
Correct answer:
A) [“apple”, “banana”, “cherry”, “date”]
Explanation: The extend() method adds all elements from another list to the end of the current list.
What will this Python code output?
x = 10
if x > 5:
print(“Greater”)
else:
print(“Smaller”)
Correct answer:
A) Greater
Explanation: Since x is greater than 5 , the condition evaluates to True , and the program prints "Greater" .
What does this Python code return?
print(min([3, 1, 2]))
Correct answer:
A) 1
Explanation: The min() function returns the smallest element in the list. In this case, the smallest number is 1 .
What will this Python code output?
x = [10, 20, 30, 40]
print(x[1:3])
Correct answer:
A) [20, 30]
Explanation: The slice [1:3] returns elements from index 1 to 3 , but not including 3 .
What does this Python code output?
print(5 + 5)
Correct answer:
B) 10
Explanation: The + operator performs addition. 5 + 5 equals 10 .
What does this Python code return?
print(type([]))
Correct answer:
A) <class ‘list’>
Explanation: An empty list is denoted by [] , and its type is <class 'list'> .
What is the result of this Python code?
print([1, 2] + [3, 4])
Correct answer:
A) [1, 2, 3, 4]
Explanation: The + operator concatenates two lists. [1, 2] + [3, 4] results in [1, 2, 3, 4] .
What does this Python code output?
x = (1, 2, 3)
print(len(x))
Correct answer:
C) 3
Explanation: The len() function returns the number of elements in a tuple. The tuple (1, 2, 3) has three elements.
What will this Python code return?
x = set([1, 2, 2, 3])
print(x)
Correct answer:
B) {1, 2, 3}
Explanation: A set contains only unique elements. Duplicates are removed automatically.
What does this Python code return?
print(“Python”.endswith(“n”))
Correct answer:
A) True
Explanation: The endswith() method checks whether a string ends with the specified suffix. "Python".endswith("n") returns True .
What will be the output of this Python code?
x = [1, 2, 3]
y = [1, 2, 3]
print(x is y)
Correct answer:
B) False
Explanation: The is operator checks whether two variables point to the same object in memory. In this case, x and y refer to different list objects, so x is y returns False .
What does this Python code return?
x = (1, 2, 3)
y = (1, 2, 3)
print(x == y)
Correct answer:
A) True
Explanation: The == operator checks whether two variables have the same value. Since both tuples have the same values, the result is True .
What will this Python code output?
x = {“a”: 1, “b”: 2}
print(x[“a”])
Correct answer:
A) 1
Explanation: The value associated with the key "a" in the dictionary is 1 .
What does this Python code return?
print(len({1, 2, 3}))
Correct answer:
C) 3
Explanation: The len() function returns the number of elements in the set {1, 2, 3} , which is 3 .
What will this Python code output?
x = [1, 2, 3]
print(x[-1])
Correct answer:
C) 3
Explanation: Negative indexing in Python allows you to access elements from the end of a list. x[-1] refers to the last element, which is 3 .
What does this Python code return?
print(“Python”.islower())
Correct answer:
B) False
Explanation: The islower() method checks whether all letters in the string are lowercase. "Python" contains uppercase letters, so it returns False .
What is the result of this Python code?
x = 10
y = 20
print(x > y)
Correct answer:
B) False
Explanation: Since x is less than y , the expression x > y evaluates to `
What does this Python code return?
print(“Hello World!”.replace(“World”, “Python”))
Correct answer:
A) Hello Python!
Explanation: The replace() method replaces occurrences of a substring with another substring. Here, "World" is replaced with "Python".
What will be the result of this Python code?
x = [1, 2, 3, 4, 5]
print(x[1:4])
Correct answer:
B) [2, 3, 4]
Explanation: The slice [1:4] returns the elements from index 1 to 3 (index 4 is excluded).
What does this Python code return?
print(type((1,)))
Correct answer:
A) <class ‘tuple’>
Explanation: A tuple with a single element requires a trailing comma, as in (1,) . Without the comma, it would be considered an integer.
What will this Python code output?
x = “12345”
print(x[::-1])
Correct answer:
A) 54321
Explanation: The slice [::-1] reverses the string by stepping through it backwards.
What is the result of this Python code?
x = [1, 2, 3]
y = [4, 5]
x.extend(y)
print(x)
Correct answer:
A) [1, 2, 3, 4, 5]
Explanation: The extend() method adds all elements from the iterable y to the end of the list x .
What will this Python code output?
x = 5
if x != 5:
print(“Not Five”)
else:
print(“Five”)
Correct answer:
B) Five
Explanation: The condition x != 5 is False because x is equal to 5 , so the else block is executed, printing "Five".
What does this Python code return?
print(“abc”.isalpha())
Correct answer:
A) True
Explanation: The isalpha() method returns True if all characters in the string are alphabetic. "abc" contains only alphabetic characters, so it returns True .
What will this Python code output?
x = {“a”: 1, “b”: 2, “c”: 3}
print(len(x))
Correct answer:
B) 3
Explanation: The len() function returns the number of key-value pairs in the dictionary, which is 3 in this case.
If this exam is giving you a hard time, let us be your helping hand. Contact us, and we'll provide the assistance you need to pass and move forward.