The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Python, you must know about this if you are related to Programming in any way. Here is the ultimate Python programming MCQ test for you that we have brought. Python is a high-level, interpreted, general-purpose programming language. The design philosophy of Python emphasizes code readability using significant indentation. Python is dynamically-typed as well as garbage-collected. Let's test your knowledge with these questions. We wish you the best of luck with this quiz.
Questions and Answers
1.
In Python, strings are…
A.
Str objects
B.
Char arrays
C.
Changeable
D.
None
Correct Answer
A. Str objects
Explanation In Python, strings are represented as str objects. This means that strings in Python are treated as a specific type of object with its own set of methods and properties. The str object allows for various operations and manipulations on strings, such as concatenation, slicing, and formatting. This is different from char arrays, which are used in some other programming languages to represent strings as arrays of individual characters. Additionally, strings in Python are immutable, meaning they cannot be changed once they are created.
Rate this question:
2.
The minsplit parameter to split() specifies the minimum number of splits to make to the input string.
A.
False
B.
True
Correct Answer
A. False
Explanation The minsplit parameter to split() does not specify the minimum number of splits to make to the input string. Instead, it specifies the maximum number of splits to make. By default, split() will make as many splits as possible.
Rate this question:
3.
Python strings have a property called “immutability." What does this mean?
A.
You can update a string in Python with concatenation.
B.
Strings in Python can be represented as arrays of char.
C.
Strings can’t be divided by numbers.
D.
Strings in Python can’t be changed.
Correct Answer
D. Strings in Python can’t be changed.
Explanation The correct answer is that strings in Python can't be changed. This means that once a string is created, its value cannot be modified. Any operation that appears to modify a string actually creates a new string with the desired modifications. This property of immutability ensures that strings are safe to use in various operations without worrying about unintended changes.
Rate this question:
4.
If you want to transform a list of strings input_list into a single string with a comma between each item, which of the following would you give as the input to join()?
A.
','
B.
Input_list
C.
Str
D.
String
Correct Answer
B. Input_list
Explanation The correct answer is "input_list" because the join() method is used to concatenate elements of a list into a single string, with the specified separator (in this case, a comma). Therefore, the input_list is the list of strings that we want to join together with commas between each item.
Rate this question:
5.
Which of the following mathematical operators can be used to concatenate strings:
A.
/
B.
*
C.
-
D.
=
Correct Answer
B. *
Explanation The mathematical operator "*" can be used to concatenate strings. In programming languages, such as Python, the "*" operator is used to repeat a string a certain number of times or to concatenate multiple copies of a string together. For example, in Python, "hello" * 3 would result in "hellohellohello", which is the concatenation of three copies of the string "hello". Therefore, the "*" operator is used for string concatenation.
Rate this question:
6.
Assume x and y are assigned as follows: x=5, y=-5. What is the effect of this statement: x, y = (y, x)[::-1]
A.
Both x and y are 5
B.
The values of x and y are swapped.
C.
The values of x and y are unchanged.
D.
Both x and y are -5
Correct Answer
C. The values of x and y are unchanged.
Explanation The statement "x, y = (y, x)[::-1]" swaps the values of x and y. However, since the assignment is done within a list slicing operation [::-1], the original order of the values is reversed and then assigned back to x and y. In this case, x=5 and y=-5, so after the statement is executed, x will be -5 and y will be 5. Therefore, the correct answer is "The values of x and y are swapped."
Rate this question:
7.
In regards to separated value files such as .csv and .tsv, what is the delimiter?
A.
Any character such as the comma (,) or tab (\t) that is used to separate the raw data
B.
Delimiters are not used in separated value files.
C.
Anywhere the comma (,) character is used in the file.
D.
Any character such as the comma (,) or tab (\t) that is used to separate the column data
Correct Answer
D. Any character such as the comma (,) or tab (\t) that is used to separate the column data
Explanation The delimiter in separated value files such as .csv and .tsv is any character such as the comma (,) or tab (\t) that is used to separate the column data.
Rate this question:
8.
In separated value files such as .csv and .tsv what does the first row in the file typically contain?
A.
The author of the table data
B.
The column names of the data
C.
The source of the data
D.
Notes about the table data
Correct Answer
B. The column names of the data
Explanation In separated value files such as .csv and .tsv, the first row in the file typically contains the column names of the data. This allows the user to easily identify and understand the data in each column. The column names provide a reference for the data that follows in the subsequent rows, making it easier to analyze and work with the data in the file.
Rate this question:
9.
Consider this assignment statement: a,b,c = (1,2,3,4,5,6,7,8,9)[1::3]. Following execution of this statement, what is the value of b:
A.
2
B.
4
C.
5
D.
6
Correct Answer
C. 5
Explanation The assignment statement is slicing the tuple (1,2,3,4,5,6,7,8,9) starting from index 1 with a step of 3. This means that it will select every third element starting from index 1. The selected elements will be (2, 5, 8). Since b is the second element in the assignment, its value will be 5.
Rate this question:
10.
Which of the following is the correct way to open the CSV file hrdata.csv for reading using the pandas package? Assume that the pandas package has already been imported.
A.
Pandas.read_csv('hrdata.csv')
B.
Pandas.open('hrdata.csv', 'r')
C.
Pandas.read_table('hrdata.csv')
D.
Pandas.open_csv('hrdata.csv', 'r')
Correct Answer
A. Pandas.read_csv('hrdata.csv')
Explanation The correct way to open the CSV file hrdata.csv for reading using the pandas package is by using the function pandas.read_csv('hrdata.csv').
Rate this question:
11.
. What is a correct syntax to output “Hello World” in Python?
A.
P("Hello, World")
B.
Echo "Hello, World"
C.
Echo ("Hello, World")
D.
Print("Hello, World")
Correct Answer
D. Print("Hello, World")
Explanation The correct syntax to output "Hello World" in Python is print("Hello, World").
Rate this question:
12.
How do you insert COMMENTS in Python code?
A.
<--this is a comment-->
B.
/*this is a comment*/
C.
#this is a comment
D.
//this is a comment//
Correct Answer
C. #this is a comment
Explanation The correct answer is "#this is a comment". In Python, the "#" symbol is used to indicate a comment. Anything written after the "#" symbol on the same line is not executed as code and is only meant for human readers to understand the code. Comments are useful for adding explanations, documenting code, and making it more readable.
Rate this question:
13.
Which collection is ordered, changeable, and allows duplicate members?
A.
TUPLE
B.
SET
C.
LIST
D.
DICTIONARY
Correct Answer
C. LIST
Explanation A list is an ordered collection in which the elements can be changed or modified. It allows duplicate members, meaning that the same value can appear multiple times in the list. This makes it a suitable choice for situations where maintaining the order of elements and allowing duplicates is necessary. Tuples, on the other hand, are ordered and allow duplicates but are immutable, meaning that their values cannot be changed once they are assigned. Sets are unordered and do not allow duplicates. Dictionaries are also unordered but consist of key-value pairs.
Rate this question:
14.
Which of the following are true about python lists?
A.
These represent the same list:
['a', 'b', 'c']
['c', 'a', 'b']
B.
All elements in a list must be of the same type
C.
A given object may appear in a list more than once
D.
There is no conceptual limit to the size of a list
Correct Answer(s)
C. A given object may appear in a list more than once D. There is no conceptual limit to the size of a list
Explanation Python lists allow duplicate elements, so a given object may appear in a list more than once. Additionally, there is no conceptual limit to the size of a list, meaning that a list can contain any number of elements.
Rate this question:
15.
Assume the following list definition:
>>> a = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge']
Several short REPL sessions are shown below. Which display correct output?
A.
· >>> print(a[4::-2])
['quux', 'baz', 'foo']
B.
· >>> a[:] is a
True
C.
· >>> print(a[-5:-3])
['bar', 'baz']
D.
· >>> max(a[2:4] + ['grault'])
'qux'
E.
· >>> print(a[-6])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
Correct Answer(s)
A. · >>> print(a[4::-2])
['quux', 'baz', 'foo']
C. · >>> print(a[-5:-3])
['bar', 'baz']
D. · >>> max(a[2:4] + ['grault'])
'qux'
Explanation The correct answers are:
- `print(a[4::-2])` prints the elements of the list `a` starting from index 4 and moving backwards by 2 steps. This results in the output `['quux', 'baz', 'foo']`.
- `print(a[-5:-3])` prints the elements of the list `a` starting from index -5 and ending at index -3. This results in the output `['bar', 'baz']`.
- `max(a[2:4] + ['grault'])` finds the maximum value among the elements of the list `a` from index 2 to index 4, along with the additional element `'grault'`. The maximum value is `'qux'`.
Rate this question:
16.
A collection which is unordered, changeable and does not allow duplicates.
A.
TUPLE
B.
SET
C.
LIST
D.
DICTIONARY
Correct Answer
D. DICTIONARY
Explanation A dictionary is a collection that is unordered, changeable, and does not allow duplicates. In Python, a dictionary is a data structure that stores key-value pairs. It is unordered because the items in a dictionary are not stored in any particular order. It is changeable because you can add, remove, or modify items in a dictionary. And it does not allow duplicates because each key in a dictionary must be unique. Therefore, a dictionary is the correct answer for a collection that possesses these characteristics.
Rate this question:
17.
A collection which is ordered and unchangeable.
A.
TUPLE
B.
SET
C.
LIST
D.
DICTIONARY
Correct Answer
A. TUPLE
Explanation A tuple is a collection in Python that is ordered and unchangeable. This means that the elements in a tuple are stored in a specific order, and once a tuple is created, its elements cannot be modified. Tuples are typically used to store related pieces of data together, such as coordinates or personal information. Unlike lists, tuples are immutable, meaning they cannot be altered after creation. Therefore, a tuple fits the description of a collection that is ordered and unchangeable.
Rate this question:
18.
How do you start writing a while loop in Python?
A.
While x > y:
B.
While (x > y)
C.
X > y while {
D.
While x>y {
Correct Answer
A. While x > y:
Explanation To start writing a while loop in Python, the correct syntax is "while x > y:". This means that the loop will continue executing as long as the condition "x > y" is true. The code block inside the loop will be executed repeatedly until the condition becomes false.
Rate this question:
19.
Select the ones you like
List a is defined as follows:
a = [1, 2, 3, 4, 5]
Select all of the following statements that remove the middle element 3 from a so that it equals [1, 2, 4, 5]:
A.
A[2]=[ ]
B.
A[2:3]=[ ]
C.
A.remove(3)
D.
A[2:2]=[ ]
E.
Del a[2]
Correct Answer(s)
B. A[2:3]=[ ] C. A.remove(3) E. Del a[2]
Explanation The correct answer is a[2:3]=[ ], a.remove(3), del a[2].
- a[2:3]=[ ]: This statement uses slicing to remove the middle element 3 from the list. It selects the element at index 2 and removes it.
- a.remove(3): This statement uses the remove() method to remove the first occurrence of the element 3 from the list.
- del a[2]: This statement uses the del keyword to delete the element at index 2 from the list.
Rate this question:
20.
Which statement is used to stop a loop?
A.
Break
B.
Exit
C.
Return
D.
Stop
Correct Answer
A. Break
Explanation The statement "break" is used to stop a loop. When the "break" statement is encountered within a loop, it immediately terminates the loop and the control is transferred to the next statement after the loop. This allows the program to exit the loop prematurely based on a certain condition, without executing the remaining iterations.
Rate this question:
21.
List a is defined as follows:
a = ['a', 'b', 'c']
Which of the following statements adds 'd' and 'e' to the end of a, so that it then equals ['a', 'b', 'c', 'd', 'e']:
A.
A.extend(['d','e'])
B.
A.append(['d','e'])
C.
A += ['d','e']
D.
A[len(a):] = ['d','e']
E.
A += 'de'
F.
A[-1:] = ['d','e']
Correct Answer(s)
A. A.extend(['d','e']) C. A += ['d','e'] D. A[len(a):] = ['d','e'] E. A += 'de'
Explanation The correct answer is a.extend(['d','e']), a += ['d','e'], a[len(a):] = ['d','e'], a += 'de'.
These options all add 'd' and 'e' to the end of the list 'a' so that it becomes ['a', 'b', 'c', 'd', 'e'].
- a.extend(['d','e']) adds the elements 'd' and 'e' to the end of list 'a' using the extend() method.
- a += ['d','e'] is shorthand for a = a + ['d','e'], which concatenates list 'a' with the list ['d','e'] and assigns the result back to 'a'.
- a[len(a):] = ['d','e'] uses list slicing to add the elements 'd' and 'e' to the end of list 'a'.
- a += 'de' concatenates the string 'de' to list 'a', resulting in ['a', 'b', 'c', 'd', 'e'].
Rate this question:
22.
Updates the dictionary with the specified key-value pairs
A.
Clear()
B.
Copy()
C.
Fromkeys()
D.
Update()
E.
Items()
Correct Answer
D. Update()
Explanation The update() method is used to update the dictionary with the specified key-value pairs. It takes in another dictionary or an iterable object containing key-value pairs as an argument and adds them to the existing dictionary. This method is useful when we want to add multiple key-value pairs to a dictionary at once, without having to add them one by one using assignment statements.
Rate this question:
23.
Returns a list of all the values in the dictionary
A.
Clear()
B.
Copy()
C.
Fromkeys()
D.
Values()
E.
Items()
Correct Answer
D. Values()
Explanation The values() method returns a list of all the values in the dictionary. This means that it will extract and return only the values from the key-value pairs in the dictionary, ignoring the keys themselves. It is useful when you need to access or manipulate only the values in a dictionary without needing to know the associated keys.
Rate this question:
24.
List is:
A.
Is a collection which is ordered and unchangeable. Allows duplicate members.
B.
Is a collection which is ordered and changeable. Allows duplicate members.
C.
Is a collection which is unordered and unindexed. No duplicate members.
D.
Is a collection which is unordered and changeable. No duplicate members.
Correct Answer
B. Is a collection which is ordered and changeable. Allows duplicate members.
Explanation The given correct answer accurately describes a list. A list is a collection that maintains the order of its elements and allows for modifications. It also allows for duplicate elements, meaning that the same value can appear multiple times in a list. This distinguishes a list from other types of collections, such as sets or dictionaries, which do not allow duplicates.
Rate this question:
25.
Tuple is
A.
Is a collection which is ordered and unchangeable. Allows duplicate members.
B.
Is a collection which is ordered and changeable. Allows duplicate members.
C.
Is a collection which is unordered and unindexed. No duplicate members.
D.
Is a collection which is unordered and changeable. No duplicate members.
Correct Answer
A. Is a collection which is ordered and unchangeable. Allows duplicate members.
Explanation A tuple is a collection that is ordered, meaning the elements have a specific sequence. It is also unchangeable, meaning once created, the elements cannot be modified. Additionally, tuples allow duplicate members, which means the same value can appear multiple times within the tuple.
Rate this question:
26.
Set is
A.
Is a collection which is ordered and unchangeable. Allows duplicate members.
B.
Is a collection which is unordered and unindexed. No duplicate members.
C.
Is a collection which is ordered and changeable. Allows duplicate members.
D.
Is a collection which is unordered and changeable. No duplicate members.
Correct Answer
B. Is a collection which is unordered and unindexed. No duplicate members.
Explanation The correct answer is "is a collection which is unordered and unindexed. No duplicate members." This statement accurately describes a set. Sets are collections where the elements are not arranged in a specific order and cannot be accessed using indexes. Additionally, sets do not allow duplicate members, meaning each element in a set is unique.
Rate this question:
27.
Dictionary is
A.
Is a collection which is unordered and changeable. No duplicate members.
B.
Is a collection which is ordered and unchangeable. Allows duplicate members.
C.
Is a collection which is ordered and changeable. Allows duplicate members.
D.
Is a collection which is unordered and unindexed. No duplicate members.
Correct Answer
A. Is a collection which is unordered and changeable. No duplicate members.
Explanation The correct answer is "is a collection which is unordered and changeable. No duplicate members." This is because a dictionary is a data structure that stores key-value pairs. It is unordered because the items in a dictionary are not stored in any particular order. It is also changeable because the items in a dictionary can be modified or updated. Additionally, a dictionary does not allow duplicate members, meaning that each key in a dictionary must be unique.
Rate this question:
28.
Suppose you have the following tuple definition:
t = ('foo', 'bar', 'baz')
Which of the following statements replaces the second element ('bar') with the string 'qux':
A.
T[1:1] = 'qux'
B.
It’s a trick question—tuples can’t be modified.
C.
T(1) = 'qux'
D.
T[1] = 'qux'
Correct Answer
B. It’s a trick question—tuples can’t be modified.
29.
Returns the number of times a specified value occurs in a tuple
A.
Index()
B.
Count()
C.
Number()
D.
Return()
Correct Answer
B. Count()
Explanation The count() function is used to return the number of times a specified value occurs in a tuple. It is a built-in function in Python that takes a single argument, which is the value to be counted. The count() function iterates through the tuple and returns the count of occurrences of the specified value.
Rate this question:
30.
Assume you have a file object my_data which has properly opened a separated value file that uses the tab character (\t) as the delimiter.
What is the proper way to open the file using the Python csv module and assign it to the variable csv_reader?
Assume that csv has already been imported.
Correct Answer
C. · csv_reader = csv.reader(my_data, delimiter='\t')
Explanation The proper way to open the file using the Python csv module and assign it to the variable csv_reader is by using the code "csv_reader = csv.reader(my_data, delimiter='\t')". This code uses the csv.reader() function to read the file object my_data and specifies the tab character (\t) as the delimiter to properly separate the values in the file.
Rate this question:
31.
When iterating over an object returned from csv.reader(), what is returned with each iteration?
For example, given the following code block that assumes csv_reader is an object returned from csv.reader(), what would be printed to the console with each iteration?
for item in csv_reader
print(item)
A.
· The row data as a list
B.
· The individual value data that is separated by the delimiter
C.
· The full line of the file as a string
D.
· The column data as a list
Correct Answer
A. · The row data as a list
Explanation When iterating over an object returned from csv.reader(), each iteration will return the row data as a list.
Rate this question:
32.
When writing to a CSV file using the .writerow() method of the csv.DictWriter object, what must each key in the input dict represent? Below is an example:
with open('test_file.csv', mode='w') as csv_file:
writer = csv.DictWriter(
csv_file,
fieldnames=['first_col', 'second_col']
)
writer.writeheader()
# This input dictionary is what the question is referring
# to and is not necessarily correct as shown.
writer.writerow({'key1':'value1', 'key2':'value2'})
A.
· Each key must match up to the field names (index names) used to identify the row data
B.
· Each key indicates the column index as an integer for where the value should go
C.
· Each key indicates the row index as an integer for where the data should go
D.
· Each key must match up to the field names (column names) used to identify the column data
Correct Answer
D. · Each key must match up to the field names (column names) used to identify the column data
Explanation Each key in the input dictionary must match up to the field names (column names) used to identify the column data. This means that the keys in the dictionary should be the same as the column names specified in the fieldnames parameter of the csv.DictWriter object. This ensures that the values are correctly mapped to the corresponding columns in the CSV file.
Rate this question:
33.
By default, pandas uses 0-based indices for indexing rows. Which of the following is the correct way to import the CSV file hrdata.csv for reading and using the 'Name' column as the index row instead?
Below is the contents of hrdata.csv
Name,Hire Date,Salary,Sick Days remaining
Fred,10/10/10,10000,10
Correct Answer(s)
A. Pandas.read_csv('hrdata.csv', index_col=0)
D. Pandas.read_csv('hrdata.csv', index_col='Name')
Explanation The correct way to import the CSV file hrdata.csv for reading and using the 'Name' column as the index row is by using the code "pandas.read_csv('hrdata.csv', index_col=0)". This code sets the index column to be the first column (0-based index) in the CSV file.
Rate this question:
34.
What is Matplotlib?
A.
Matplotlib is a high level graph plotting library in python that serves as a visualization utility.
B.
Matplotlib is a high level graph plotting library in python that serves as a calculation utility.
C.
Matplotlib is a low level graph plotting library in python that serves as a visualization utility.
D.
Matplotlib is a low level graph plotting library in python that serves as a calculation utility.
Correct Answer
C. Matplotlib is a low level grapH plotting library in python that serves as a visualization utility.
Explanation Matplotlib is a low level graph plotting library in python that serves as a visualization utility. It provides a wide range of tools for creating various types of plots, such as line plots, bar plots, scatter plots, histograms, and more. With Matplotlib, users have the flexibility to customize their plots with different colors, styles, labels, and annotations. It is widely used in the scientific and data analysis community for data visualization and exploration.
Rate this question:
35.
What will be the output of the following code : print type(type(int))
A.
Type 'int'
B.
Type 'type'
C.
Error
D.
0
Correct Answer
B. Type 'type'
Explanation The output of the code will be "type 'type'". The code is using the "type" function to get the type of the "int" class, which is itself a class. So, the type of "int" is "type", and when we print the type of "type", it will give us "type 'type'".
Rate this question:
36.
What is called when a function is defined inside a class?
A.
Class
B.
Module
C.
Another function
D.
Method
Correct Answer
D. Method
Explanation A function defined inside a class is called a method. In object-oriented programming, a method is a behavior associated with an object or a class. It represents the actions that an object or class can perform. By defining a function within a class, we can encapsulate related functionality and access the properties and other methods of the class. This allows for better organization and structure in the code, making it easier to maintain and reuse.
Rate this question:
37.
Which of the following is the use of id() function in python?
A.
Every object doesn't have unique id
B.
Id returns the identity of the object
C.
All of the mentioned
D.
None of the mentioned
Correct Answer
B. Id returns the identity of the object
Explanation The id() function in Python is used to return the identity of an object. This identity is a unique integer that is assigned to each object when it is created. It can be used to differentiate between different objects and check if two objects are the same or not. Therefore, the correct answer is "Id returns the identity of the object".
Rate this question:
38.
Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.pop(1)?
A.
[1, 3, 3, 4, 5, 5, 20, 25]
B.
[3, 4, 5, 20, 5, 25, 1, 3]
C.
[3, 5, 20, 5, 25, 1, 3]
D.
[1, 3, 4, 5, 20, 5, 25]
Correct Answer
C. [3, 5, 20, 5, 25, 1, 3]
Explanation After executing the code `list1.pop(1)`, the element at index 1 (which is 4) is removed from the list. Therefore, the resulting list is [3, 5, 20, 5, 25, 1, 3].
Rate this question:
39.
Time.time() returns ___
A.
The current time in milliseconds since midnight, January 1, 1970
B.
The current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time)
C.
The current time
D.
The current time in milliseconds since midnight
Correct Answer
B. The current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time)
Explanation time.time() returns the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time).
Rate this question:
40.
Consider the results of a medical experiment that aims to predict whether someone is going to develop myopia based on some physical measurements and heredity. In this case, the input dataset consists of the person’s medical characteristics and the target variable is binary: 1 for those who are likely to develop myopia and 0 for those who aren’t. This can be best classified as
A.
Regression
B.
Clustering
C.
Association Rules
D.
Decision tree
Correct Answer
D. Decision tree
Explanation The given scenario involves predicting whether someone is going to develop myopia based on physical measurements and heredity. This is a classification problem as the target variable is binary: 1 for those likely to develop myopia and 0 for those who aren't. Decision tree algorithms are commonly used for classification tasks, making it the best choice among the given options. Decision trees can effectively handle binary classification problems by creating a tree-like model that splits the data based on different features to make predictions.
Rate this question:
41.
Which function overloads the >> operator?
A.
More()
B.
None of the above
C.
Gt()
D.
Ge()
Correct Answer
B. None of the above
Explanation The correct answer is "None of the above." This is because the question is asking about which function overloads the >> operator, and none of the given options (more(), gt(), ge()) are valid overloads for this operator. The >> operator is typically overloaded for input operations, such as reading data from a stream or input device.
Rate this question:
42.
Which operator is overloaded by the or() function?
A.
|
B.
\\
C.
||
D.
//
Correct Answer
A. |
Explanation The correct answer is "||". The "or()" function is overloaded by the "||" operator.
Rate this question:
43.
Given a function that does not return any value, what value is shown when executed at the shell?
A.
Int
B.
Void
C.
None
D.
Bool
Correct Answer
C. None
Explanation When a function does not return any value, it means that it does not have a specific value to show when executed at the shell. Therefore, the value shown when executing this function at the shell is "none".
Rate this question:
44.
Which module in Python supports regular expressions?
A.
Regex
B.
Pyregex
C.
Repyregex
D.
Re
Correct Answer
D. Re
Explanation The correct answer is "re". The "re" module in Python supports regular expressions. It provides several functions and methods to work with regular expressions, such as searching for patterns, matching strings, and replacing patterns in strings. By importing and using the "re" module, Python programmers can efficiently work with regular expressions in their code.
Rate this question:
45.
Which of the following is not a complex number?
A.
K = 2 + 3l
B.
K = 2 + 3j
C.
K=complex(2,3)
D.
K = 2 + 3J
Correct Answer
A. K = 2 + 3l
Explanation The given expression "k = 2 + 3l" is not a complex number because the variable "l" is not a standard notation for representing the imaginary unit. The standard notation for the imaginary unit is "i" or "j". Therefore, "k = 2 + 3l" does not fit the form of a complex number and is not a valid option.
Rate this question:
46.
What does ~~~~5 evaluate to?
A.
+5
B.
-11
C.
-5
D.
+11
Correct Answer
A. +5
Explanation The given expression ~~~~5 evaluates to +5. The tilde (~) operator in many programming languages is used to perform a bitwise negation operation. In this case, the expression ~~5 is equivalent to 5, as the first tilde negates the second tilde, resulting in the original value. Therefore, the additional two tildes have no effect, and the final result is +5.
Rate this question:
47.
Given a string s= “Welcome” , which of the following code is incorrect?
A.
Print s[0]
B.
S[1]='r'
C.
Print s.lower()
D.
Fprint s.strip()
Correct Answer
B. S[1]='r'
Explanation The code s[1]='r' is incorrect because strings in Python are immutable, meaning they cannot be changed. Therefore, trying to assign a new value to a specific index in a string will result in an error.
Rate this question:
48.
Which one is NOT a legal variable name?
A.
_myvar
B.
My-var
C.
Myvar
D.
My_var
Correct Answer
B. My-var
Explanation The variable name "my-var" is not a legal variable name because it contains a hyphen, which is not allowed in variable names. Variable names can only contain letters, numbers, and underscores, and they cannot start with a number. Therefore, "my-var" does not meet the requirements of a legal variable name.
Rate this question:
49.
How do you create a variable with the numeric value 5?
A.
X=5
B.
X=int(5)
C.
Both the other answers are correct
D.
None is correct
Correct Answer
C. Both the other answers are correct
Explanation Both options "x=5" and "x=int(5)" are valid ways to create a variable with the numeric value 5. The first option assigns the value directly to the variable, while the second option converts the value to an integer before assigning it to the variable. Therefore, both options are correct ways to create a variable with the numeric value 5.
Rate this question:
50.
What is the correct file extension for Python files?
A.
.py
B.
.pt
C.
.pyt
D.
.pyth
Correct Answer
A. .py
Explanation The correct file extension for Python files is .py. This extension is commonly used to identify Python scripts or programs.
Rate this question:
Quiz Review Timeline +
Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.