What is the output of len("Python") in Python?
Correct answer:
B) 6
Explanation: The len() function returns the number of characters in the string, which is 6 in this case.
What is the output of len("Python") in Python?
Correct answer:
B) 6
Explanation: The len() function returns the number of characters in the string, which is 6 in this case.
Which method is used to add an element to the end of a list?
Correct answer:
B) append()
Explanation: The append() method adds an element to the end of a list.
What is the result of 5 // 2 in Python?
Correct answer:
C) 2
Explanation: The // operator performs floor division and returns the largest integer less than or equal to the result.
Which operator is used to compare if two values are equal in Python?
Correct answer:
B) ==
Explanation: The == operator compares two values for equality in Python.
What does the str() function do in Python?
Correct answer:
B) Converts an integer to a string
Explanation: The str() function converts an integer or any other data type to a string.
How do you start a comment in Python?
Correct answer:
A) #
Explanation: Comments in Python start with the # symbol.
What is the output of print("hello".capitalize())?
Correct answer:
A) Hello
Explanation: The capitalize() method returns a copy of the string with the first character capitalized and the rest lowercased.
How do you remove the last element from a list in Python?
Correct answer:
C) pop()
Explanation: The pop() method removes and returns the last element of a list.
What is the correct way to create a dictionary in Python?
Correct answer:
C) my_dict = {'a': 1, 'b': 2}
Explanation: A dictionary is created using curly braces {} with key-value pairs.
What is the result of 10 % 4?
Correct answer:
C) 2
Explanation: The % operator returns the remainder of the division, so 10 % 4 equals 2.
What does the input() function do in Python?
Correct answer:
B) Receives user input from the keyboard
Explanation: The input() function is used to take input from the user as a string.
Which method can be used to convert a list into a set in Python?
Correct answer:
C) set()
Explanation: The set() function converts a list into a set, which is an unordered collection of unique elements.
What is the output of print('Python'.lower())?
Correct answer:
B) python
Explanation: The lower() method converts all characters in a string to lowercase.
How do you define a tuple in Python?
Correct answer:
C) my_tuple = (1, 2, 3)
Explanation: A tuple is created using parentheses, like (1, 2, 3).
What does the isalpha() method do?
Correct answer:
A) Checks if all characters in a string are alphabetic
Explanation: The isalpha() method returns True if all characters in the string are alphabetic and False otherwise.
How do you create an empty set in Python?
Correct answer:
D) set = set()
Explanation: An empty set is created using the set() function. Using {} creates an empty dictionary, not a set.
What does the split() method do?
Correct answer:
B) Splits a string into a list based on a delimiter
Explanation: The split() method divides a string into a list, breaking at the specified delimiter.
What will be the result of 3 + 2 * 4?
Correct answer:
C) 11
Explanation: In Python, multiplication has a higher precedence than addition, so 2 * 4 is evaluated first, followed by 3 + 8.
What is a list comprehension in Python?
Correct answer:
B) A way to create lists based on existing lists
Explanation: List comprehensions provide a concise way to generate lists from existing lists or other iterables.
How do you create a single-line comment in Python?
Correct answer:
D) # This is a comment
Explanation: Single-line comments in Python start with the # symbol.
What is the result of round(4.67)?
Correct answer:
B) 5
Explanation: The round() function rounds a number to the nearest integer, so 4.67 is rounded up to 5.
How do you reverse a string in Python?
Correct answer:
C) [::-1]
Explanation: The slicing syntax [::-1] reverses the string.
Which of the following is a mutable data type in Python?
Correct answer:
B) List
Explanation: Lists are mutable, meaning their elements can be changed after creation, while tuples, strings, and integers are immutable.
What does the update() method do in Python?
Correct answer:
B) Updates a dictionary by adding or modifying key-value pairs
Explanation: The update() method in dictionaries adds new key-value pairs or updates existing ones.
How do you remove leading and trailing whitespace from a string in Python?
Correct answer:
A) strip()
Explanation: The strip() method removes whitespace from the beginning and end of a string.
What is the result of 2 ** 3 in Python?
Correct answer:
B) 8
Explanation: The ** operator is used for exponentiation, so 2 ** 3 equals 2 * 2 * 2, which is 8.
Which function is used to find the largest number in a list?
Correct answer:
A) max()
Explanation: The max() function returns the largest value in a list or other iterable.
What is a key characteristic of a set in Python?
Correct answer:
C) It is mutable
Explanation: A set is mutable, meaning its elements can be added or removed, but it does not allow duplicate elements.
How do you find the data type of a variable in Python?
Correct answer:
A) type()
Explanation: The type() function returns the data type of the given variable.
What is the output of print(list(range(3)))?
Correct answer:
B) [0, 1, 2]
Explanation: The range() function generates numbers starting from 0, and range(3) returns [0, 1, 2].
Which method returns the number of elements in a list?
Correct answer:
D) len()
Explanation: The len() function returns the number of elements in a list.
What does the continue statement do in a loop?
Correct answer:
B) Skips the current iteration and continues with the next one
Explanation: The continue statement skips the remaining code in the current iteration and proceeds to the next iteration of the loop.
How do you check if a key exists in a dictionary?
Correct answer:
A) if key in dict:
Explanation: The in operator checks if a key exists in a dictionary.
Which function converts a number into a floating-point number?
Correct answer:
C) float()
Explanation: The float() function converts a number into a floating-point number.
How do you declare a global variable inside a function in Python?
Correct answer:
B) global var_name
Explanation: The global keyword is used to declare a global variable inside a function.
What does the startswith() method do?
Correct answer:
B) Checks if a string starts with a specified value
Explanation: The startswith() method returns True if the string starts with the specified prefix.
What is the output of print("Hello " + "World")?
Correct answer:
B) Hello World
Explanation: The + operator concatenates the two strings with no additional spaces, so the output is "Hello World".
How do you sort a list in ascending order?
Correct answer:
D) Both a and b
Explanation: You can use either list.sort() or sorted(list) to sort a list in ascending order. The former modifies the list in place, while the latter returns a new sorted list.
What will print(bool("")) return?
Correct answer:
B) False
Explanation: An empty string is considered False in a Boolean context in Python.
Which keyword is used to handle exceptions in Python?
Correct answer:
C) try
Explanation: The try keyword is used to handle exceptions in Python. It is typically followed by except.
How do you access a value in a dictionary using a key?
Correct answer:
D) Both a and c
Explanation: You can access a value in a dictionary using either dict[key] or dict.get(key).
What is the output of print(7 % 3)?
Correct answer:
B) 1
Explanation: The % operator returns the remainder of the division, so 7 % 3 equals 1.
Which function is used to iterate over a sequence with an index in Python?
Correct answer:
A) enumerate()
Explanation: The enumerate() function allows you to loop over a sequence and get both the index and the element.
How do you check if all elements in a list are true?
Correct answer:
B) all(list)
Explanation: The all() function returns True if all elements in the list are true.
What is the purpose of the finally block in Python?
Correct answer:
B) Executes code after a try block, regardless of whether an exception was raised
Explanation: The finally block is always executed after the try and except blocks, whether an exception occurs or not.
How do you create a function with variable-length arguments in Python?
Correct answer:
A) def my_function(*args):
Explanation: The *args syntax allows you to pass a variable number of arguments to a function.
What does the zip() function do in Python?
Correct answer:
B) Joins two or more lists element-wise
Explanation: The zip() function combines two or more iterables element by element into tuples.
How do you remove a key from a dictionary?
Correct answer:
A) del dict[key]
Explanation: The del statement removes a key-value pair from a dictionary.
What is the correct way to call a method from a class instance in Python?
Correct answer:
B) object.method()
Explanation: To call a method from a class instance, you use the syntax object.method().
What does the is operator do in Python?
Correct answer:
B) Compares if two variables point to the same object
Explanation: The is operator checks if two variables refer to the same object in memory.
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.