Basic to Advanced Python MCQ question and answer

For fetch the data, which function we use to run the select query in SQLite?
a) fetch()
b) rawquery()
c) executequery()
d) execute()
Answer: d) execute()

__________ parameter has to be the first parameter of any function in the class.
a) itself
b) self
c) myself
d) this
Answer: b) self

A collection in MongoDB is the same as a __________ in SQL databases.
a) Database
b) Record
c) Table
d) None of the Above
Answer: c) Table

How to convert numpy array to list?
a) array.list()
b) array.list
c) list.array()
d) list(array)
Answer: d) list(array)

How to create a function with variable length argument?
a) [args]
b) *args
c) *(args)
d) None of the above
Answer: c) *(args)

How to find the type of numpy array?
a) type(array)
b) dtype
c) objects.type(array)
d) numpy(type)
Answer: c) objects.type(array)

Matplotlib is __________ plotting library.
a) 1D
b) 2D
c) 3D
d) All of the above
Answer: c) 3D

Missing data in Pandas object is represented through:
a) Null
b) None
c) Missing
d) NaN
Answer: d) NaN

MongoDB waits until you have created a __________, with at least one record before it actually creates the database.
a) collection
b) document
c) record
d) None of the abobe
Answer: a) collection

Pandas key data structure is called?
a) Keyframe
b) DataFrame
c) Statistics
d) Econometrics
Answer: b) DataFrame

reshape() function in numpy array using python is:
a) reshape(shape)
b) array.reshape(shape)
c) reshape(array,shape)
d) numpy.reshape(array)
Answer: b) array.reshape(shape)

The axis 0 identifies a dataframe’s __________.
a) rows
b) columns
c) values
d) data type
Answer: a) rows

The command to install Matplotlib library in Python is
a) install pip matplotlib
b) install matplotlib
c) pip matplotlib
d) pip install matplotlib
Answer: d) pip install matplotlib

The command used to give a heading to a graph is __________.
a) plt.show()
b) plt.plot()
c) plt.xlabel()
d) plt.title()
Answer: d) plt.title()

The most important object defined in NumPy is an N-dimensional array type called?
a) ndarray
b) narray
c) nd_array
d) darray
Answer: a) ndarray

The plot which tells the trend between two graphed variables is the __________ chart.
a) line
b) scatter
c) bar
d) pie
Answer: a) line

To add a new element to a list we use which command?
a) list1.add(5)
b) list1.append(5)
c) list1.addLast(5)
d) list1.addEnd(5)
Answer: b) list1.append(5)

To compare data we can use __________ chart
a) Line
b) Bar
c) Pie
d) Scatter
Answer: b) Bar

To Delete a row from a DataFrame you may use __________ Statement.
a) remove
b) del
c) drop
d) cancel
Answer: c) drop

To get the number of elements in a dataframe __________ attribute may be used.
a) size
b) shape
c) values
d) ndim
Answer: c) drop

To get the transpose of a dataframe D1, you can write __________.
a) D1.T
b) D1.Transpose
c) D1.Swap
d) All of the above
Answer: a) D1.T

To open or connect with the database, which function we used or call at runtime in SQLite?
a) open()
b) connect()
c) database()
d) All of the above
Answer: b) connect()

To serialize an object hierarchy, the __________ function must be called. To deserialize a data stream, the __________ function must be called.
a) dumps(), undumps()
b) loads(), unloads()
c) loads(), dumps()
d) dumps(), loads()
Answer: d) dumps(), loads()

To specify the style of line as dashed, Which argument of plot() needs to be set ?
a) line
b) width
c) style
d) linestyle
Answer: d) linestyle

We will use __________ class in Python to load and parse XML file.
a) XML Parser
b) XML minidom
c) Socket
d) createElement
Answer: b) XML minidom

What does the function re.search do?
a) matches a pattern at the start of the string.
b) matches a pattern at any position in the string.
c) such a function does not exist.
d) none of the mentioned.
Answer: b) matches a pattern at any position in the string.

What is the output of “hello”+1+2+3 ?
a) hello123
b) hello
c) Error
d) hello6
Answer: c) Error

What is the output of print str[2:] if str = ‘Hello World!’?
a) llo World!
b) H
c) llo
d) None of the above.
Answer: a) llo World!

What is the output of the following? a = [0, 1, 2, 3] for a[-1] in a: print(a[-1])
a = [0, 1, 2, 3]
for a[-1] in a:
print(a[-1])

a) 0 1 2 3
b) 0 1 2 2
c) 3 3 3 3
d) Error
Answer: b) 0 1 2 2

What is the use of tell() method in python?
a) tells you the current position within the file
b) tells you the end position within the file
c) tells you the file is opened or not
d) None of the above
Answer: a) tells you the current position within the file

What will be correct syntax for pandas series?
a) pandas_Series(data, index, dtype, copy)
b) pandas.Series(data, index, dtype)
c) pandas.Series(data, index, dtype, copy)
d) pandas_Series(data, index. dtype)
Answer: c) pandas.Series(data, index, dtype, copy)

What will be displayed by print(ord(‘b’) ? ord(‘a’))?
a) 0
b) 1
c) -1
d) 2
Answer: b) 1

What will be the output?
d={“john”:40, “peter”:45}
print(list(d.keys()))

a) [“john”,”peter”]
b) [“john”:40,”peter”:45]
c) (“john”,”peter”)
d) (“john”:40,”peter”:45)
Answer: a) [“john”,”peter”]

What will be the output?

my_tuple = (1, 2, 3, 4)
my_tuple.append( (5, 6, 7))
print len(my_tuple)

a) 1
b) 2
c) 5
d) Error
Answer: d) Error

What will be the output?
print(2*t) [When t=(1,2)]
a) (1, 2, 1, 2)
b) [1, 2, 1, 2]
c) (1, 1, 2, 2)
d) [1, 1, 2, 2]
Answer: a) (1, 2, 1, 2)

Which function attribute is used to returns the doc string defined in the function source code.
a) __doc__
b) doc
c) __int__
d) init
Answer: a) __doc__

That’s It! We hope you find the MCQs helpful. Watch this space for additional content in the future. Do not forget to share this post on social media. Until next time, happy browsing!

WhatsApp
Copy link
URL has been copied successfully!