Which Python function can be used to return the absolute value of a number?
Correct answer:
A) abs()
Explanation: The abs() function returns the absolute value of a number. It removes any negative sign, leaving only the magnitude of the number.
Which Python function can be used to return the absolute value of a number?
Correct answer:
A) abs()
Explanation: The abs() function returns the absolute value of a number. It removes any negative sign, leaving only the magnitude of the number.
What will be the result of the following code snippet?
x = 10
y = 5
print(x // y)
Correct answer:
B) 2
Explanation: The // operator performs floor division, meaning it divides the numbers and rounds down to the nearest whole number. 10 // 5 results in 2 .
What is the output of the following Python code?
print(“Hello”[1])
Correct answer:
B) e
Explanation: Strings in Python are zero-indexed, meaning the first character is at index 0 . So "Hello"[1] accesses the second character, which is 'e' .
What will be the output of this code?
print(2 ** 3)
Correct answer:
B) 8
Explanation: The ** operator is used for exponentiation. 2 ** 3 means 2 raised to the power of 3, which equals 8.
Which Python function is used to read input from the user?
Correct answer:
A) input()
Explanation: The input() function reads a line of text entered by the user and returns it as a string.
What is the result of this expression?
result = “Python” + “3”
print(result)
Correct answer:
B) Python3
Explanation: The + operator concatenates strings. "Python" + "3" results in the string 'Python3' .
What does the following Python code return?
len([1, 2, 3, 4, 5])
Correct answer:
B) 5
Explanation: The len() function returns the number of elements in a list. [1, 2, 3, 4, 5] contains 5 elements, so the result is 5 .
What does the following code return?
name = “Alice”
print(name.upper())
Correct answer:
A) ALICE
Explanation: The upper() method converts all lowercase characters in a string to uppercase. 'Alice' becomes 'ALICE' .
What does this code do?
numbers = [1, 2, 3]
numbers.append(4)
print(numbers)
Correct answer:
B) [1, 2, 3, 4]
Explanation: The append() method adds an item to the end of a list. In this case, the number 4 is added to the list [1, 2, 3] .
What will be the result of this Python code?
x = 5
y = 10
x, y = y, x
print(x, y)
Correct answer:
B) 10 5
Explanation: The code swaps the values of x and y . After the swap, x holds the value 10 and y holds the value 5 .
What does this code return?
print(10 % 3)
Correct answer:
A) 1
Explanation: The % operator returns the remainder of the division. 10 % 3 results in 1 , because 10 divided by 3 gives a remainder of 1.
What is the correct way to define a function in Python?
Correct answer:
B) def myFunc():
Explanation: Functions in Python are defined using the def keyword followed by the function name and parentheses.
What does this code output?
print(type(5.0))
Correct answer:
B) <class ‘float’>
Explanation: The type() function returns the type of the given object. 5.0 is a floating-point number, so its type is <class 'float'> .
What will this code return?
list1 = [1, 2, 3]
list2 = list1
list2.append(4)
print(list1)
Correct answer:
B) [1, 2, 3, 4]
Explanation: In Python, lists are mutable and variables can refer to the same object. Since list2 is a reference to list1 , appending to list2 will also modify list1 .
What is the output of this code?
print(bool(0))
Correct answer:
B) False
Explanation: In Python, 0 is considered False when converted to a Boolean. Non-zero numbers are considered True .
What is the result of this Python code?
print(2 * 3 ** 2)
Correct answer:
B) 18
Explanation: Exponentiation is done before multiplication, so 3 ** 2 = 9 , and then 2 * 9 = 18 .
Which of the following is the correct syntax for a comment in Python?
Correct answer:
C) # This is a comment
Explanation: In Python, comments start with the # symbol. Anything after the # on the same line is ignored by the interpreter.
What will this code output?
name = “Bob”
print(name * 3)
Correct answer:
A) BobBobBob
Explanation: In Python, the * operator can be used to repeat a string a specified number of times. In this case, 'Bob' is repeated 3 times.
What will the following Python code return?
print(bool(“False”))
Correct answer:
A) True
Explanation: In Python, non-empty strings are considered True when evaluated in a Boolean context, even if the string is "False" .
Which of the following data types is immutable in Python?
Correct answer:
D) Tuple
Explanation: Tuples in Python are immutable, meaning their elements cannot be changed once the tuple is created. Lists, dictionaries, and sets are mutable.
What will be the output of this code?
numbers = [1, 2, 3, 4, 5]
print(numbers[-1])
Correct answer:
B) 5
Explanation: Negative indexing starts from the end of the list. numbers[-1] accesses the last element, which is 5 .
What is the output of the following Python code?
x = [1, 2, 3]
y = [1, 2, 3]
print(x is y)
Correct answer:
B) False
Explanation: Even though x and y have the same contents, they are different objects in memory. The is operator checks for object identity, not value equality.
What does the following code return?
print(2 in [1, 2, 3])
Correct answer:
A) True
Explanation: The in keyword checks for membership. Since 2 is an element of the list [1, 2, 3] , the result is True .
What will this Python code output?
x = “Python”
print(x[2:])
Correct answer:
C) thon
Explanation: The slice [2:] starts from index 2 and goes to the end of the string. In 'Python' , index 2 corresponds to 't' .
What will this code output?
print(type([1, 2, 3]))
Correct answer:
B) <class ‘list’>
Explanation: The type() function returns the type of the object. [1, 2, 3] is a list, so the output will be <class 'list'> .
Which of the following is a valid Python variable name?
Correct answer:
C) first_place
Explanation: Python variable names cannot start with a digit, contain spaces, or use hyphens. The name first_place is valid.
What does this Python code do?
my_dict = {“name”: “Alice”, “age”: 25}
print(my_dict[“name”])
Correct answer:
B) Prints Alice
Explanation: The dictionary my_dict stores values associated with keys. my_dict["name"] accesses the value associated with the key "name" , which is "Alice" .
What is the result of this Python code?
print(“Hello”.lower())
Correct answer:
C) hello
Explanation: The lower() method converts all characters in the string to lowercase. "Hello" becomes "hello" .
What will the following code output?
print(3 * ‘A’)
Correct answer:
B) AAA
Explanation: The * operator can be used to repeat a string. 'A' * 3 results in the string 'AAA' .
What does the following code return?
print(type((1, 2, 3)))
Correct answer:
B) <class ‘tuple’>
Explanation: The type of (1, 2, 3) is a tuple. The type() function returns <class 'tuple'> .
What will be the output of this code?
print(“Python”[::-1])
Correct answer:
B) nohtyP
Explanation: The slice [::-1] reverses the string. The result is the reversed version of "Python" , which is "nohtyP" .
What will this Python code output?
for i in range(3):
print(i, end=”, “)
Correct answer:
B) 0, 1, 2,
Explanation: The end=", " argument in the print() function adds a comma and space after each printed value, including the last one.
What does this Python code do?
x = [1, 2, 3]
y = x.copy()
y.append(4)
print(x)
Correct answer:
A) Prints [1, 2, 3]
Explanation: The copy() method creates a shallow copy of the list x . Changes to y do not affect the original list x .
Which operator is used to concatenate strings in Python?
Correct answer:
A) +
Explanation: The + operator is used to concatenate two strings in Python.
What will be the output of this code?
print(10 / 4)
Correct answer:
B) 2.5
Explanation: The / operator performs true division and returns a floating-point number. 10 / 4 equals 2.5 .
What will this Python code return?
fruits = [“apple”, “banana”, “cherry”]
fruits.insert(1, “orange”)
print(fruits)
Correct answer:
A) [“apple”, “orange”, “banana”, “cherry”]
Explanation: The insert() method inserts an element at a specified position in the list. "orange" is inserted at index 1 .
What will be the result of this Python code?
x = [1, 2, 3]
x.remove(2)
print(x)
Correct answer:
B) [1, 3]
Explanation: The remove() method removes the first occurrence of the specified element from the list. In this case, 2 is removed.
What does this Python code return?
print(type({1, 2, 3}))
Correct answer:
C) <class ‘set’>
Explanation: The curly braces {} denote a set in Python. The type() function returns <class 'set'> for {1, 2, 3} .
What is the result of this Python expression?
x = “123”
print(x.isdigit())
Correct answer:
A) True
Explanation: The isdigit() method returns True if all characters in the string are digits. "123" contains only digits, so the result is True .
What will this Python code return?
print([1, 2, 3] + [4, 5, 6])
Correct answer:
C) [1, 2, 3, 4, 5, 6]
Explanation: The + operator concatenates two lists in Python. [1, 2, 3] + [4, 5, 6] results in [1, 2, 3, 4, 5, 6] .
What does this Python code output?
print(“Hello”.replace(“l”, “r”))
Correct answer:
A) Herro
Explanation: The replace() method replaces occurrences of a substring in a string. All occurrences of "l" are replaced with "r" , resulting in "Herro"
What is the result of this code?
print([1, 2, 3] * 2)
Correct answer:
A) [1, 2, 3, 1, 2, 3]
Explanation: The * operator can be used to repeat lists. [1, 2, 3] * 2 results in a new list that repeats the original list twice: [1, 2, 3, 1, 2, 3] .
What will be the result of this Python code?
numbers = [1, 2, 3, 4, 5]
print(numbers[1:3])
Correct answer:
B) [2, 3]
Explanation: The slice [1:3] includes elements from index 1 to 3 , but not including index 3 . This gives the sublist [2, 3] .
What will this Python code return?
x = [“apple”, “banana”, “cherry”]
x.pop(1)
print(x)
Correct answer:
A) [“apple”, “cherry”]
Explanation: The pop() method removes an element at a specific index. x.pop(1) removes "banana" from the list.
What does the following Python code output?
for i in range(1, 6):
if i == 3:
continue
print(i, end=” “)
Correct answer:
A) 1 2 4 5
Explanation: The continue statement skips the rest of the loop for the current iteration. When i == 3 , the loop continues without printing 3 .
What does this code return?
print([i**2 for i in range(3)])
Correct answer:
A) [0, 1, 4]
Explanation: The list comprehension [i**2 for i in range(3)] squares each number in the range from 0 to 2. The result is [0**2, 1**2, 2**2] , which is [0, 1, 4] .
What does this Python code return?
print(5 == 5.0)
Correct answer:
A) True
Explanation: In Python, integers and floats are considered equal if they represent the same numerical value. 5 and 5.0 are equal, so the result is True .
What does the following Python code return?
print(“,”.join([“a”, “b”, “c”]))
Correct answer:
A) a,b,c
Explanation: The join() method concatenates the elements of the list with the specified delimiter. In this case, the elements "a" , "b" , and "c" are joined by commas.
What will this code output?
print({1, 2, 3}.union({3, 4}))
Correct answer:
A) {1, 2, 3, 4}
Explanation: The union() method returns a set that contains all unique elements from both sets. The result is {1, 2, 3, 4} .
What will the following Python code output?
print(type(range(5)))
Correct answer:
C) <class ‘range’>
Explanation: The range() function returns an object of type <class 'range'> , which represents a sequence of numbers.
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.