1.
Which keyword allows us to load a module in Python?
Correct Answer
A. Import
Explanation
The keyword "import" allows us to load a module in Python. It is used to bring in functionality from other modules into our current program. By using the "import" keyword, we can access the functions, classes, or variables defined in the module and use them in our code.
2.
Which one from the following objects in Python is immutable?
Correct Answer
C. Tuple
Explanation
A tuple is immutable in Python, meaning that once it is created, its elements cannot be changed. This is in contrast to lists, dictionaries, and sets, which are mutable and can be modified after creation.
3.
Give the output of the following code.
a = "Python Quiz"
print(a[2:5])
Correct Answer
B. Tho
Explanation
The code is using string slicing to print a portion of the string "Python Quiz". The slicing notation a[2:5] means to start at the index 2 (inclusive) and end at the index 5 (exclusive). So, it will print the characters at index 2, 3, and 4, which are "t", "h", and "o" respectively. Therefore, the output will be "tho".
4.
The ________ module is used for creating and manipulating DataFrames in Python.
Correct Answer
C. Pandas
Explanation
The Pandas module is used for creating and manipulating DataFrames in Python. It provides high-performance, easy-to-use data structures and data analysis tools. With Pandas, users can efficiently handle and analyze large datasets, perform data cleaning and transformation, and perform various statistical operations. It is widely used in data science and data analysis tasks due to its flexibility and powerful features.
5.
Which one of the following operators can perform floor division in Python?
Correct Answer
D. // -
Explanation
The operator "//" in Python is used to perform floor division. Floor division returns the largest integer that is less than or equal to the division of two numbers. It discards the decimal part of the division and only returns the whole number part.
6.
Which function can add elements to the end of a list?
Correct Answer
C. Append()
Explanation
The append() function is used to add elements to the end of a list. It takes a single argument, which is the element to be added, and appends it to the end of the list. This function is commonly used when you want to add new elements to an existing list without changing the order of the existing elements.
7.
Give the output of the following code.
for i in range(0,10,3):
print(i)
Correct Answer
B. 0 3 6 9
Explanation
The code uses a for loop to iterate through the range from 0 to 10 with a step of 3. The print statement inside the loop prints the current value of i. Since the range starts at 0 and increments by 3, the output will be 0, 3, 6, and 9.
8.
Using the ________ statement, we can come out of a for loop in Python.
Correct Answer
A. Break
Explanation
The break statement in Python is used to exit a loop prematurely. When the break statement is encountered within a for loop, the loop is immediately terminated, and the program execution continues with the next statement after the loop. Therefore, using the break statement allows us to exit a for loop in Python.
9.
What is the syntax of accessing a value using its key in Python?
Correct Answer
C. Dictionary_name[key]
Explanation
The correct syntax for accessing a value using its key in Python is dictionary_name[key]. This syntax allows you to retrieve the value associated with a specific key in a dictionary. By using the square brackets and the key inside them, you can access the corresponding value in the dictionary.
10.
Give the output of the following code.
lst = ['Mark','Jay',' Jack','Steve','Arnold']
print(lst[-2])
Correct Answer
B. Steve
Explanation
The code is creating a list called "lst" with the values 'Mark', 'Jay', 'Jack', 'Steve', and 'Arnold'. The code then prints the value at index -2 of the list, which is 'Steve'.
11.
How to make comments in Python?
Correct Answer
D. #This is a comment
Explanation
In Python, comments can be declared using the "#" symbol. The given answer "#This is a comment" correctly demonstrates the declaration of a comment in Python.
12.
Which operator has the highest precedence in the following?
Correct Answer
A. * multiplication operator
Explanation
The multiplication operator (*) has the highest precedence among the given operators. This means that when an expression contains multiple operators, the multiplication operator will be evaluated first before the addition operator (+), bitwise AND operator (&), and comparison operator (==).
13.
Give the output of the following code.
c = 2 ** 3 + 4 * 2
print(c)
Correct Answer
B. 16
Explanation
The code calculates the value of c using the mathematical operations in the expression. First, it performs the exponentiation operation 2 ** 3, which equals 8. Then, it multiplies 4 by 2, resulting in 8 as well. Finally, it adds the two results together, giving a final value of 16.
14.
Which one of the following functions can sort a list in Python?
Correct Answer
B. Sorted()
Explanation
The sorted() function in Python can sort a list. It takes a list as input and returns a new list with the elements sorted in ascending order. Therefore, out of the given options, sorted() is the correct function to use for sorting a list in Python.