What will print(10 // 3) output in Python?
Correct answer:
A) 3
Explanation: The // operator performs floor division, which returns the largest integer less than or equal to the result of the division.
What will print(10 // 3) output in Python?
Correct answer:
A) 3
Explanation: The // operator performs floor division, which returns the largest integer less than or equal to the result of the division.
Which of the following creates an empty list in Python?
Correct answer:
B) list = []
Explanation: An empty list is created using square brackets [] .
What is the output of print(‘hello’.upper()) in Python?
Correct answer:
B) HELLO
Explanation: The upper() method converts all characters of a string to uppercase.
Which method is used to combine the contents of two dictionaries in Python?
Correct answer:
B) dict.update()
Explanation: The update() method adds key-value pairs from one dictionary to another.
What will print([1, 2, 3] + [4, 5]) output in Python?
Correct answer:
A) [1, 2, 3, 4, 5]
Explanation: Using + concatenates two lists into a single list.
What is the correct syntax for defining a function in Python?
Correct answer:
C) def function_name():
Explanation: Functions in Python are defined using the def keyword followed by the function name and parentheses () .
How do you add a single element to a set in Python?
Correct answer:
A) set.add()
Explanation: The add() method adds a single element to a set.
What is the correct way to check if an element is in a list in Python?
Correct answer:
A) element in list
Explanation: The in keyword checks if an element exists in a list.
Which of the following is a tuple in Python?
Correct answer:
C) (1, 2, 3)
Explanation: A tuple is defined using parentheses () .
What does the clear() method do for a list in Python?
Correct answer:
C) Removes all elements from the list
Explanation: The clear() method empties the list by removing all elements.
Which method can be used to combine all elements in a list into a single string?
Correct answer:
B) join()
Explanation: The join() method concatenates the elements of a list into a single string, with a separator between each element.
How do you define a multi-line comment in Python?
Correct answer:
C) ”’ comment ”’
Explanation: Multi-line comments in Python are written using triple quotes ''' .
What is the output of print(type(42)) ?
Correct answer:
A) int
Explanation: The type() function returns the type of the object, and 42 is an integer.
How do you access the first element of a tuple t = (10, 20, 30) ?
Correct answer:
A) t[0]
Explanation: Tuples are indexed similarly to lists, and the first element has an index of 0 .
Which operator is used to check if two values are the same object in memory?
Correct answer:
C) is
Explanation: The is operator checks if two variables refer to the same object in memory.
What is the output of bool(None) in Python?
Correct answer:
B) False
Explanation: None evaluates to False in a Boolean context.
How do you check if a list is empty in Python?
Correct answer:
D) Both b and c
Explanation: You can check if a list is empty by using either len(list) == 0 or if not list , which evaluates to True if the list is empty.
What is the output of print(“abc” * 3) ?
Correct answer:
A) abcabcabc
Explanation: Multiplying a string by an integer repeats the string that many times.
Which of the following creates a dictionary in Python?
Correct answer:
B) d = {}
Explanation: An empty dictionary is created using curly braces {} .
What does the sorted() function do in Python?
Correct answer:
B) Returns a sorted list
Explanation: The sorted() function returns a new list with elements in sorted order without modifying the original list.
What is the result of list(“hello”) in Python?
Correct answer:
A) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
Explanation: The list() function converts a string into a list of individual characters.
How do you retrieve all the keys from a dictionary in Python?
Correct answer:
A) dict.keys()
Explanation: The keys() method returns a view object containing all the keys of a dictionary.
Which operator is used to get the remainder of a division in Python?
Correct answer:
C) %
Explanation: The % operator returns the remainder of a division
What will be the output of print(3 ** 2) ?
Correct answer:
B) 9
Explanation: The ** operator is used for exponentiation, and 3 ** 2 equals 9.
How do you convert a list of strings into a single string separated by commas?
Correct answer:
B) ‘,’.join(list)
Explanation: The join() method is used to concatenate list elements with a specified separator.
How do you find the minimum value in a list in Python?
Correct answer:
A) min()
Explanation: The min() function returns the smallest element in a list.
What is the result of len(“Hello World”) ?
Correct answer:
B) 11
Explanation: The len() function counts all characters in the string, including spaces, making it 11 characters long.
What is the default value of a global variable in Python?
Correct answer:
B) None
Explanation: Global variables are initialized to None by default if not assigned a value.
Which of the following is not a valid list method in Python?
Correct answer:
D) add()
Explanation: The add() method is used for sets, not lists.
What is the output of print(type([])) in Python?
Correct answer:
C) list
Explanation: An empty pair of square brackets [] creates an empty list in Python.
How do you remove the last element from a list in Python?
Correct answer:
A) list.pop()
Explanation: The pop() method removes and returns the last element of a list.
What will print(range(5)) output in Python 3?
Correct answer:
B) range(0, 5)
Explanation: In Python 3, range() returns a range object, not a list.
How do you raise an exception in Python?
Correct answer:
A) raise Exception(“Error”)
Explanation: The raise statement is used to trigger an exception.
What is the output of print(“Hello”.replace(“l”, “L”)) ?
Correct answer:
B) HeLLo
Explanation: The replace() method replaces all occurrences of the substring "l" with "L" .
How do you declare a global variable inside a function in Python?
Correct answer:
A) global x
Explanation: The global keyword is used to declare a global variable inside a function.
What is the result of print(len([])) ?
Correct answer:
A) 0
Explanation: An empty list has a length of 0.
Which keyword is used to handle exceptions in Python?
Correct answer:
B) try
Explanation: The try block lets you test a block of code for exceptions.
What is the output of print(“A” in “Apple”) ?
Correct answer:
A) True
Explanation: The in operator checks if a substring exists within another string, and A is in "Apple" .
What is the result of int(“42.5”) ?
Correct answer:
C) Error
Explanation: You cannot directly convert a string with a decimal point to an integer.
How do you concatenate two tuples in Python?
Correct answer:
A) +
Explanation: The + operator concatenates two tuples.
What is the output of print(bool(0)) ?
Correct answer:
B) False
Explanation: In Python, 0 evaluates to False in a Boolean context.
How do you check if a set is a subset of another set in Python?
Correct answer:
B) set <= other_set
Explanation: The <= operator checks if one set is a subset of another.
Which method is used to remove an element from a set in Python?
Correct answer:
D) Both a and c
Explanation: The remove() and discard() methods both remove an element from a set, but discard() does not raise an error if the element is not found.
What does the any() function do in Python?
Correct answer:
B) Returns True if any element in an iterable is true
Explanation: The any() function returns True if at least one element of the iterable is true.
What will be the result of print({1, 2, 3} & {2, 3, 4}) ?
Correct answer:
A) {2, 3}
Explanation: The & operator returns the intersection of two sets.
Which of the following can be used as a dictionary key in Python?
Correct answer:
B) Tuple
Explanation: Dictionary keys must be immutable types, and tuples are immutable, while lists, sets, and dictionaries are mutable.
What is the result of max([10, 20, 30]) ?
Correct answer:
C) 30
Explanation: The max() function returns the largest element from a list.
How do you read a file line by line in Python?
Correct answer:
D) for line in file:
Explanation: Using a for loop allows you to read a file line by line efficiently.
What is the result of print(2 ** 3 ** 2) ?
Correct answer:
B) 512
Explanation: Exponentiation is evaluated from right to left, so 3 ** 2 is 9, and 2 ** 9 equals 512.
What does the strip() method do in Python?
Correct answer:
C) Removes both leading and trailing whitespace
Explanation: The strip() method removes whitespace from both the beginning and end of a string.
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.