100% found this document useful (3 votes)
3K views

Python Basic, Numpy, Panda-Mcq - Key

The document contains 30 multiple choice questions about Python and Pandas basics. The questions cover topics like basic Python programming concepts (print statements, functions, conditionals), NumPy arrays (creation, operations, reshaping), and Pandas DataFrames and Series (creation, indexing, summary operations).

Uploaded by

Ram Kannuu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
3K views

Python Basic, Numpy, Panda-Mcq - Key

The document contains 30 multiple choice questions about Python and Pandas basics. The questions cover topics like basic Python programming concepts (print statements, functions, conditionals), NumPy arrays (creation, operations, reshaping), and Pandas DataFrames and Series (creation, indexing, summary operations).

Uploaded by

Ram Kannuu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PYTHON BASIC MCQ

1.What is the output of the following program?

y=8

z = lambda x: x * y

print z (6)

A. 48
B. 14
C. 64
D. None of the above

2.What is the output of the following program?

import re
sentence = 'horses are fast'
regex = re.compile('(?P<animal>w+) (?P<verb>w+) (?P<adjective>w+)')
matched = re.search(regex, sentence)
print(matched.groupdict())
A. {‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
B. (‘horses’, ‘are’, ‘fast’)
C. ‘horses are fast’
D. ‘are’

3.What is the output of the following code?

print 9//2

A. 4.5
B. 4.0
C. 4
D. Error

4.Which operator is overloaded by the or () function?

A. ||
B. |
C. //
D. /

5. What is the output of the following program?

print 0.1 + 0.2 == 0.3


A. True
B. False
C. Machine dependent
D. Error

6.What is the output of the following program?

print "Hello World"[::-1]

A. dlroW olleH
B. Hello Worl
C. d
D. Error

7.What data type is the object below? L = [1, 23, ‘hello’, 1]

A. List
B. Dictionary
C. Tuple
D. Array

8.What is the output of the following program?

def myfunc(a):

a=a+2

a=a*2

return a

print myfunc(2)

A. 8
B. 16
C. Indentation Error
D. Runtime Error

9.What is the output of the following program?

print '{0:.2}’. format (1.0 / 3)

A. 0.333333
B. 0.33
C. 0.333333: -2
D. Error
10.What is the output of the following program?

i=0

while i < 3:

print i

i += 1

else:

print 0

A. 01230
B. 0120
C. 012
D. Error

11.What is the output of the following program?

import numpy as np

np.zeros((2,2))

A. array ([[0., 0.], [0., 0.]])


B. array ([[0., 0.])
C. array ([0., 0.], [0., 0.])
D. error

12.What is the output of the following program?

import numpy as np

e = np.array([(1,2,3), (4,5,6)])

print(e)

e.reshape(3,2)

A. array([[1, 2],[3, 4],[5, 6]])


B. array([[1, 2],[5, 6]],[3, 4])
C. array([[5, 6]],[1, 2],[3, 4])
D. error
13.What is the output of the following program?

## Horitzontal Stack

import numpy as np

f = np.array([1,2,3])

g = np.array([4,5,6])

print('Horizontal Append:', np.hstack((f, g)))

A. Horizontal Append: [4 5 6 1 2 3]
B. Horizontal Append: [1 2 3 4 5 6]
C. Horizontal Append: [1 2 3]
D. All the above

14.What is the output of the following program?

x = np.array([1,2,3], dtype=np.complex128)

x.itemsize

A. 16
B. 61
C. 6
D. Error

15.What is the output of the following program?

f = np.array([1,2])

g = np.array([4,5])

np.dot(f, g)

A. 31
B. 12
C. 14
D. Error

16.What is the output of the following program?

h = [[1,2],[3,4]]

i = [[5,6],[7,8]]

np.matmul(h, i)

A. array([[43, 50],[19, 22]])


B. array([[19, 22],[43, 50]])
C. error
D. All the above
17.What is the output of the following program?

import numpy np

np.arange(1, 11)

A. array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])


B. array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
C. array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
D. error

18.What is the output of the following program?

np.linspace(1.0, 5.0, num=5, endpoint=False)

A. array([1. , 1.8, 2.6, 3.4, 4.2])


B. array([1. , 1.8, 2.6, 3.4, 4.2, 5])
C. error
D. All the above

19.What is the output of the following program?

import numpy as np

x = np.array([[1, 2], [3, 4], [5, 6]])

y = x [[0,1,2], [0,1,0]]

print y

A. [5 4 1]
B. [1 4 5]
C. [4 1 5]
D. Error

20.What is the output of the following program?

import numpy as np

print np.var([1,2,3,4])

A. 1.25
B. 1
C. 1.0
D. Error
21.What is the output of the following program?

import pandas as pd

s = pd.Series([1,2,3,4,5],index = ['a','b','c','d','e'])

print s[0]

A. 1
B. 0
C. 2
D. Error

22.What is the output of the following program?

import pandas as pd

import numpy as np

df = pd.DataFrame(index=[0,1,2,3,4,5],columns=['one','two'])

print df['one']. sum ()

A. 0
B. nan
C. error
D. All the above

23.What is the output of the following program?

import pandas as pd

print pd.Timestamp('2017-03-01')

A. 2017-03-01 00:00
B. 2017-03-01 00:00:00
C. 2017-03-01 00:01
D. All the above

24.What is the output of the following program?

import pandas as pd

import numpy as np

cat = pd.Categorical(["a", "c", "c", np.nan], categories=["b", "a", "c"])

print cat.ordered

A. True
B. False
C. Error
D. All the above
25.What is the output of the following program?

import pandas as pd

if pd.Series([False, True, False]).any():

print ("I am any")

A. I am any
B. I any
C. any
D. Error

26.Which of the following input can be accepted by DataFrame ?

A. Structured ndarray
B. Series
C. DataFrame
D. All of the Mentioned

27.Which of the following takes a dict of dicts or a dict of array-like sequences and returns a
DataFrame ?

A. DataFrame.from_items
B. DataFrame.from_records
C. DataFrame.from_dict
D. All of the Mentioned

28.Point out the wrong statement:

A. A DataFrame is like a fixed-size dict in that you can get and set values by index label
B. Series can be be passed into most NumPy methods expecting an ndarray
C. A key difference between Series and ndarray is that operations between Series
automatically align the data based on label
D. None of the Mentioned

29.If data is an ndarray, index must be the same length as data.

A. True
B. False

30. 1. Which of the following thing can be data in Pandas?

A. a python dict
B. a ndarray
C. a scalar value
D. all of the Mentioned

You might also like