0% found this document useful (0 votes)
118 views

MCQ Python

Uploaded by

xfactor8056
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views

MCQ Python

Uploaded by

xfactor8056
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 130

MCQ PYTHON

1.
What is the maximum length of a Python identifier?
32
16
128
No fixed length is specified.
Check Answer
2.
What will be the output of the following code snippet?
print(2**3 + (5 + 6)**(1 + 1))
129
8
121
None of the above.
Check Answer
3.
What will be the datatype of the var in the below code snippet?
var = 10
print(type(var))
var = "Hello"
print(type(var))
str and int
int and int
str and str
int and str
Check Answer
4.
How is a code block indicated in Python?
Brackets.
Indentation.
Key.
None of the above.
Check Answer
5.
What will be the output of the following code snippet?
a = [1, 2, 3]
a = tuple(a)
a[0] = 2
print(a)
[2, 2, 3]
(2, 2, 3)
(1, 2, 3)
Error.
Check Answer
6.
What will be the output of the following code snippet?
print(type(5 / 2))
print(type(5 // 2))
float and int
int and float
float and float
int and int
Check Answer
7.
What will be the output of the following code snippet?
a = [1, 2, 3, 4, 5]
sum = 0
for ele in a:
sum += ele
print(sum)
15
0
20
None of these
Check Answer
8.
What will be the output of the following code snippet?
count = 0
while(True):
if count % 3 == 0:
print(count, end = " ")
if(count > 15):
break;
count += 1
0 1 2 ….. 15
Infinite Loop
0 3 6 9 12 15
0 3 6 9 12
Check Answer
9.
Which of the following concepts is not a part of Python?
Pointers.
Loops.
Dynamic Typing.
All of the above.
Check Answer
10.
What will be the output of the following code snippet?
def solve(a, b):
return b if a == 0 else solve(b % a, a)
print(solve(20, 50))
10
20
50
1
Check Answer
11.
What will be the output of the following code snippet?
def solve(a):
a = [1, 3, 5]
a = [2, 4, 6]
print(a)
solve(a)
print(a)
[2, 4, 6]. [2, 4, 6]
[2, 4, 6], [1, 3, 5]
[1. 3. 5], [1, 3, 5]
None of these.
Check Answer
12.
What will be the output of the following code snippet?
def func():
global value
value = "Local"

value = "Global"
func()
print(value)
Local
Global
None
Cannot be predicted
Check Answer
13.
Which of the following statements are used in Exception Handling in Python?
try
except
finally
All of the above
Check Answer
14.
What will be the output of the following code snippet?
a = 3
b = 1
print(a, b)
a, b = b, a
print(a, b)
31 13
31 31
13 13
13 31
Check Answer
15.
Which of the following types of loops are not supported in Python?
for
while
do-while
None of the above
Check Answer
16.
Which of the following is the proper syntax to check if a particular element is present
in a list?
if ele in list
if not ele not in list
Both A and B
None of the above
Check Answer
17.
What will be the output of the following code snippet?
def thrive(n):
if n % 15 == 0:
print("thrive", end = “ ”)
elif n % 3 != 0 and n % 5 != 0:
print("neither", end = “ ”)
elif n % 3 == 0:
print("three", end = “ ”)
elif n % 5 == 0:
print("five", end = “ ”)
thrive(35)
thrive(56)
thrive(15)
thrive(39)
five neither thrive three
five neither three thrive
three three three three
five neither five neither
Check Answer
18.
What will be the output of the following code snippet?
def check(a):
print("Even" if a % 2 == 0 else "Odd")

check(12)
Even
Odd
Error
None
Check Answer
19.
What will be the output of the following code snippet?
example = ["Sunday", "Monday", "Tuesday", "Wednesday"];
print(example[-3:-1])
['Monday', 'Tuesday']
['Sunday', 'Monday']
['Tuesday', 'Wednesday']
['Wednesday', 'Monday']
Check Answer
20.
What will be the output of the following code snippet?
a = [1, 2]
print(a * 3)
Error
[1, 2]
[1, 2, 1, 2]
[1, 2, 1, 2, 1, 2]
Check Answer
21.
What will be the output of the following code snippet?
example = ["Sunday", "Monday", "Tuesday", "Wednesday"];
del example[2]
print(example)
['Sunday', 'Monday', 'Tuesday', 'Wednesday']
['Sunday', 'Monday', 'Wednesday']
['Monday', 'Tuesday', 'Wednesday']
['Sunday', 'Monday', 'Tuesday']
Check Answer
22.
What will be the type of the variable sorted_numbers in the below code snippet?
numbers = (4, 7, 19, 2, 89, 45, 72, 22)
sorted_numbers = sorted(numbers)
print(sorted_numbers)
List
Tuple
String
Int
Check Answer
23.
What will be the output of the following code snippet?
numbers = (4, 7, 19, 2, 89, 45, 72, 22)
sorted_numbers = sorted(numbers)
even = lambda a: a % 2 == 0
even_numbers = filter(even, sorted_numbers)
print(type(even_numbers))
filter
int
list
tuple
Check Answer
24.
What will be the output of the following code snippet?
numbers = (4, 7, 19, 2, 89, 45, 72, 22)
sorted_numbers = sorted(numbers)
odd_numbers = [x for x in sorted_numbers if x % 2 != 0]
print(odd_numbers)
[7, 19, 45, 89]
[2, 4, 22, 72]
[4, 7, 19, 2, 89, 45,72, 22]
[2, 4, 7, 19, 22, 45, 72, 89]
Check Answer
25.
What will be the output of the following code snippet?
def is_even(number):
message = f"{number} is an even number" if number % 2 == 0 else
f"{number} is an odd number"
return message
print(is_even(54))
54 is an even number
54 is an odd number
number is an even number
number is an odd number
Check Answer
26.
What will be the output of the following code snippet?
dict1 = {'first' : 'sunday', 'second' : 'monday'}
dict2 = {1: 3, 2: 4}
dict1.update(dict2)
print(dict1)
{'first': 'sunday', 'second': 'monday', 1: 3, 2: 4}
{'first': 'sunday', 'second': 'monday'}
{1: 3, 2: 4}
None of the above.
Check Answer
27.
What will be the output of the following code snippet?
s = {1, 2, 3, 3, 2, 4, 5, 5}
print(s)
{1, 2, 3, 3, 2, 4, 5, 5}
{1, 2, 3, 4, 5}
None
{1, 5}
Check Answer
28.
What will be the output of the following code snippet?
a = {'Hello':'World', 'First': 1}
b = {val: k for k , val in a.items()}
print(b)
{'Hello':'World', 'First': 1}
{'World': 'Hello', 1: 'First'}
Can be both A or B
None of the above
Check Answer
29.
Which of the following functions converts date to corresponding time in Python?
strptime()
strftime()
Both A and B
None of the above
Check Answer
30.
What will be the output of the following code snippet?
word = "Python Programming"
n = len(word)
word1 = word.upper()
word2 = word.lower()
converted_word = ""
for i in range(n):
if i % 2 == 0:
converted_word += word2[i]
else:
converted_word += word1[i]
print(converted_word)
pYtHoN PrOgRaMmInG
Python Programming
python programming
PYTHON PROGRAMMING
Check Answer
31.
What will be the output of the following code snippet?
a = "4, 5"
nums = a.split(',')
x, y = nums
int_prod = int(x) * int(y)
print(int_prod)
20
45
54
4,5
Check Answer
32.
What will be the output of the following code snippet?
square = lambda x: x ** 2
a = []
for i in range(5):
a.append(square(i))

print(a)
[0, 1, 4, 9, 16]
[1, 4, 9, 16, 25]
[0, 1, 2, 3, 4]
[1, 2, 3, 4, 5]
Check Answer
33.
What will be the output of the following code snippet?
def tester(*argv):
for arg in argv:
print(arg, end = ' ')
tester('Sunday', 'Monday', 'Tuesday', 'Wednesday')
Sunday
Wednesday
Sunday Monday Tuesday Wednesday
None of the above.
Check Answer
34.
As what datatype are the *args stored, when passed into a function?
List.
Tuple.
Dictionary.
None of the above.
Check Answer
35.
What will be the output of the following code snippet?
def tester(**kwargs):
for key, value in kwargs.items():
print(key, value, end = " ")
tester(Sunday = 1, Monday = 2, Tuesday = 3, Wednesday = 4)
Sunday 1 Monday 2 Tuesday 3 Wednesday 4
Sunday 1
Wednesday 4
None of the above
Check Answer
36.
As what datatype are the *kwargs stored, when passed into a function?
Lists.
Tuples.
Dictionary.
None of the above.
Check Answer
37.
Which of the following blocks will always be executed whether an exception is
encountered or not in a program?
try
except
finally
None of These
Check Answer
38.
What will be the output of the following code snippet?
from math import *
a = 2.19
b = 3.999999
c = -3.30
print(int(a), floor(b), ceil(c), fabs(c))
2 3 -3 3.3
3 4 -3 3
2 3 -3 3
2 3 -3 -3.3
Check Answer
39.
What will be the output of the following code snippet?
set1 = {1, 3, 5}
set2 = {2, 4, 6}
print(len(set1 + set2))
3
6
0
Error
Check Answer
40.
What keyword is used in Python to raise exceptions?
raise
try
goto
except
Check Answer
41.
What will be the output of the following code snippet?
s1 = {1, 2, 3, 4, 5}
s2 = {2, 4, 6}
print(s1 ^ s2)
{1, 2, 3, 4, 5}
{1, 3, 5, 6}
{2, 4}
None of the above
Check Answer
42.
Which of the following is not a valid set operation in python?
Union
Intersection
Difference
None of the above
Check Answer
43.
What will be the output of the following code snippet?
a = [1, 2, 3, 4]
b = [3, 4, 5, 6]
c = [x for x in a if x not in b]
print(c)
[1, 2]
[5, 6]
[1, 2, 5, 6]
[3, 4]
Check Answer
44.
Which of the following are valid escape sequences in Python?
\n
\t
\\
All of the above
Check Answer
45.
Which of the following are valid string manipulation functions in Python?
count()
upper()
strip()
All of the above
Check Answer
46.
Which of the following modules need to be imported to handle date time
computations in Python?
datetime
date
time
timedate
Check Answer
47.
How can assertions be disabled in Python?
Passing -O when running Python.
Assertions are disabled by default.
Both A and B are wrong.
Assertions cannot be disabled in Python.
Check Answer
48.
What will be the output of the following code snippet?
a = [[], "abc", [0], 1, 0]
print(list(filter(bool, a)))
['abc', [0], 1]
[1]
[“abc”]
None of the above
Check Answer
49.
In which language is Python written?
C++
C
Java
None of these
Check Answer
50.
What will be the result of the following expression in Python “2 ** 3 + 5 ** 2”?
65536
33
169
None of these
Check Answer

1) What is the maximum possible length of an identifier?

a. 16
b. 32
c. 64
d. None of these above

Show Answer Workspace

2) Who developed the Python language?

a. Zim Den
b. Guido van Rossum
c. Niene Stom
d. Wick van Rossum

Show Answer Workspace

3) In which year was the Python language developed?

a. 1995
b. 1972
c. 1981
d. 1989

Show Answer Workspace

4) In which language is Python written?

PlayNext
Unmute

Current Time 0:00

Duration 18:10
Loaded: 0.37%
Â
Fullscreen
Backward Skip 10sPlay VideoForward Skip 10s

a. English
b. PHP
c. C
d. All of the above

Show Answer Workspace

5) Which one of the following is the correct extension of the Python file?

a. .py
b. .python
c. .p
d. None of these

Show Answer Workspace


6) In which year was the Python 3.0 version developed?

a. 2008
b. 2000
c. 2010
d. 2005

Show Answer Workspace

7) What do we use to define a block of code in Python language?

a. Key
b. Brackets
c. Indentation
d. None of these

Show Answer Workspace

8) Which character is used in Python to make a single line comment?

a. /
b. //
c. #
d. !

Show Answer Workspace

9) Which of the following statements is correct regarding the object-oriented programming


concept in Python?

a. Classes are real-world entities while objects are not real


b. Objects are real-world entities while classes are not real
c. Both objects and classes are real-world entities
d. All of the above
Show Answer Workspace

10) Which of the following statements is correct in this python code?

1. class Name:
2. def __init__(javatpoint):
3. javajavatpoint = java
4. name1=Name("ABC")
5. name2=name1

a. It will throw the error as multiple references to the same object is not possible
b. id(name1) and id(name2) will have same value
c. Both name1 and name2 will have reference to two different objects of class Name
d. All of the above

Show Answer Workspace

11) What is the method inside the class in python language?

a. Object
b. Function
c. Attribute
d. Argument

Show Answer Workspace

12) Which of the following declarations is incorrect?

a. _x = 2
b. __x = 3
c. __xyz__ = 5
d. None of these

Show Answer Workspace


13) Why does the name of local variables start with an underscore discouraged?

a. To identify the variable


b. It confuses the interpreter
c. It indicates a private variable of a class
d. None of these

Show Answer Workspace

14) Which of the following is not a keyword in Python language?

a. val
b. raise
c. try
d. with

Show Answer Workspace

15) Which of the following statements is correct for variable names in Python language?

a. All variable names must begin with an underscore.


b. Unlimited length
c. The variable name length is a maximum of 2.
d. All of the above

Show Answer Workspace

16) Which of the following declarations is incorrect in python language?

a. xyzp = 5,000,000
b. x y z p = 5000 6000 7000 8000
c. x,y,z,p = 5000, 6000, 7000, 8000
d. x_y_z_p = 5,000,000
Show Answer Workspace

17) Which of the following words cannot be a variable in python language?

a. _val
b. val
c. try
d. _try_

Show Answer Workspace

18) Which of the following operators is the correct option for power(ab)?

a. a^b
b. a**b
c. a ^ ^ b
d. a ^ * b

Show Answer Workspace

19) Which of the following precedence order is correct in Python?

a. Parentheses, Exponential, Multiplication, Division, Addition, Subtraction


b. Multiplication, Division, Addition, Subtraction, Parentheses, Exponential
c. Division, Multiplication, Addition, Subtraction, Parentheses, Exponential
d. Exponential, Parentheses, Multiplication, Division, Addition, Subtraction

Show Answer Workspace

20) Which one of the following has the same precedence level?

a. Division, Power, Multiplication, Addition and Subtraction


b. Division and Multiplication
c. Subtraction and Division
d. Power and Division

Show Answer Workspace

21) Which one of the following has the highest precedence in the expression?

a. Division
b. Subtraction
c. Power
d. Parentheses

Show Answer Workspace

22) Which of the following functions is a built-in function in python language?

a. val()
b. print()
c. print()
d. None of these

Show Answer Workspace

23) Study the following function:

1. round(4.576)

What will be the output of this function?

a. 4
b. 5
c. 576
d. 5

Show Answer Workspace


24) Which of the following is correctly evaluated for this function?

1. pow(x,y,z)

a. (x**y) / z
b. (x / y) * z
c. (x**y) % z
d. (x / y) / z

Show Answer Workspace

25) Study the following function:

1. all([2,4,0,6])

What will be the output of this function?

a. False
b. True
c. 0
d. Invalid code

Show Answer Workspace

26) Study the following program:

1. x = 1
2. while True:
3. if x % 5 = = 0:
4. break
5. print(x)
6. x+=1

What will be the output of this code?


a. error
b. 2 1
c. 0 3 1
d. None of these

Show Answer Workspace

27) Which one of the following syntaxes is the correct syntax to read from a simple text file
stored in ''d:\java.txt''?

a. Infile = open(''d:\\java.txt'', ''r'')


b. Infile = open(file=''d:\\\java.txt'', ''r'')
c. Infile = open(''d:\java.txt'',''r'')
d. Infile = open.file(''d:\\java.txt'',''r'')

Show Answer Workspace

28) Study the following code:

1. x = ['XX', 'YY']
2. for i in a:
3. i.lower()
4. print(a)

What will be the output of this program?

a. ['XX', 'YY']
b. ['xx', 'yy']
c. [XX, yy]
d. None of these

Show Answer Workspace

29) Study the following function:


1. import math
2. abs(math.sqrt(36))

What will be the output of this code?

a. Error
b. -6
c. 6
d. 6.0

Show Answer Workspace

30) Study the following function:

1. any([5>8, 6>3, 3>1])

What will be the output of this code?

a. False
b. Ture
c. Invalid code
d. None of these

Show Answer Workspace

31) Study the following statement:

1. >>>"a"+"bc"

What will be the output of this statement?

a. a+bc
b. abc
c. a bc
d. a
Show Answer Workspace

32) Study the following code:

1. >>>"javatpoint"[5:]

What will be the output of this code?

a. javatpoint
b. java
c. point
d. None of these

Show Answer Workspace

33) The output to execute string.ascii_letters can also be obtained from:?

a. character
b. ascii_lowercase_string.digits
c. lowercase_string.upercase
d. ascii_lowercase+string.ascii_upercase

Show Answer Workspace

34) Study the following statements:

1. >>> str1 = "javat"


2. >>> str2 = ":"
3. >>> str3 = "point"
4. >>> str1[-1:]

What will be the output of this statement?

a. t
b. j
c. point
d. java

Show Answer Workspace

35) Study the following code:

1. >>> print (r"\njavat\npoint")

What will be the output of this statement?

a. java
point
b. java point
c. \njavat\npoint
d. Print the letter r and then javat and then point

Show Answer Workspace

36) Study the following statements:

1. >>> print(0xA + 0xB + 0xC)

What will be the output of this statement?

a. 33
b. 63
c. 0xA + 0xB + 0xC
d. None of these

Show Answer Workspace

37) Study the following program:

1. class book:
2. def __init__(a, b):
3. a.o1 = b
4.
5. class child(book):
6. def __init__(a, b):
7. a.o2 = b
8.
9. obj = page(32)
10. print "%d %d" % (obj.o1, obj.o2)

Which of the following is the correct output of this program?

a. 32
b. 32 32
c. 32 None
d. Error is generated

Show Answer Workspace

38) Study the following program:

1. class Std_Name:
2. def __init__(self, Std_firstName, Std_Phn, Std_lastName):
3. self.Std_firstName = Std_firstName
4. self. Std_PhnStd_Phn = Std_Phn
5. self. Std_lastNameStd_lastName = Std_lastName
6.
7. Std_firstName = "Wick"
8. name = Std_Name(Std_firstName, 'F', "Bob")
9. Std_firstName = "Ann"
10. name.lastName = "Nick"
11. print(name.Std_firstName, name.Std_lastName)

What will be the output of this statement?


a. Ann Bob
b. Ann Nick
c. Wick Bob
d. Wick Nick

Show Answer Workspace

39) Study the following statements:

1. >>> print(ord('h') - ord('z'))

What will be the output of this statement?

a. 18
b. -18
c. 17
d. -17

Show Answer Workspace

40) Study the following program:

1. x = ['xy', 'yz']
2. for i in a:
3. i.upper()
4. print(a)

Which of the following is correct output of this program?

a. ['xy', 'yz']
b. ['XY', 'YZ']
c. [None, None]
d. None of these

Show Answer Workspace


41) Study the following program:

1. i = 1:
2. while True:
3. if i%3 == 0:
4. break
5. print(i)

Which of the following is the correct output of this program?

a. 123
b. 3 2 1
c. 1 2
d. Invalid syntax

Show Answer Workspace

42) Study the following program:

1. a = 1
2. while True:
3. if a % 7 = = 0:
4. break
5. print(a)
6. a += 1

Which of the following is correct output of this program?

a. 12345
b. 1 2 3 4 5 6
c. 1 2 3 4 5 6 7
d. Invalid syntax

Show Answer Workspace


43) Study the following program:

1. i = 0
2. while i < 5:
3. print(i)
4. i += 1
5. if i == 3:
6. break
7. else:
8. print(0)

What will be the output of this statement?

a. 123
b. 0 1 2 3
c. 0 1 2
d. 3 2 1

Show Answer Workspace

44) Study the following program:

1. i = 0
2. while i < 3:
3. print(i)
4. i += 1
5. else:
6. print(0)

What will be the output of this statement?

a. 01
b. 0 1 2
c. 0 1 2 0
d. 0 1 2 3

Show Answer Workspace

45) Study the following program:

1. z = "xyz"
2. j = "j"
3. while j in z:
4. print(j, end=" ")

What will be the output of this statement?

a. xyz
b. No output
c. x y z
d. j j j j j j j..

Show Answer Workspace

46) Study the following program:

1. x = 'pqrs'
2. for i in range(len(x)):
3. x[i].upper()
4. print (x)

Which of the following is the correct output of this program?

a. PQRS
b. pqrs
c. qrs
d. None of these

Show Answer Workspace


47) Study the following program:

1. d = {0: 'a', 1: 'b', 2: 'c'}


2. for i in d:
3. print(i)

What will be the output of this statement?

a. abc
b. 0 1 2
c. 0 a 1 b 2 c
d. None of these above

Show Answer Workspace

48) Study the following program:

1. d = {0, 1, 2}
2. for x in d:
3. print(x)

What will be the output of this statement?

a. {0, 1, 2} {0, 1, 2} {0, 1, 2}


b. 0 1 2
c. Syntax_Error
d. None of these above

Show Answer Workspace

49) Which of the following option is not a core data type in the python language?

a. Dictionary
b. Lists
c. Class
d. All of the above

Show Answer Workspace

50) What error will occur when you execute the following code?

1. MANGO = APPLE

a. NameError
b. SyntaxError
c. TypeError
d. ValueError

Show Answer Workspace

51) Study the following program:

1. def example(a):
2. aa = a + '1'
3. aa = a*1
4. return a
5. >>>example("javatpoint")

What will be the output of this statement?

a. hello2hello2
b. hello2
c. Cannot perform mathematical operation on strings
d. indentationError

Show Answer Workspace

52) Which of the following data types is shown below?

1. L = [2, 54, 'javatpoint', 5]


What will be the output of this statement?

a. Dictionary
b. Tuple
c. List
d. Stack

Show Answer Workspace

53) What happens when '2' == 2 is executed?

a. False
b. Ture
c. ValueError occurs
d. TypeError occurs

Show Answer Workspace

54) Study the following program:

1. try:
2. if '2' != 2:
3. raise "JavaTpoint"
4. else:
5. print("JavaTpoint has not exist")
6. except "JavaTpoint":
7. print ("JavaTpoint has exist")

What will be the output of this statement?

a. invalid code
b. JavaTpoint has not exist
c. JavaTpoint has exist
d. none of these above
Show Answer Workspace

55) Study the following statement

1. z = {"x":0, "y":1}

Which of the following is the correct statement?

a. x dictionary z is created
b. x and y are the keys of dictionary z
c. 0 and 1 are the values of dictionary z
d. All of the above

1) Study the following program:

1. print(print(print("javatpoint")))

What will be the output of this program?

a. javatpoint None None


b. None None javatpoint
c. None javatpoint None
d. Javatpoint

Show Answer Workspace

2) Study the following program:

1. print(True ** False / True)

What will be the output of this program?

PlayNext
Unmute
Current Time 12:35

Duration 18:10
Loaded: 74.85%
Â
Fullscreen
Backward Skip 10sPlay VideoForward Skip 10s

a. True ** False / True


b. 1.0
c. 1 ** 0 / 1
d. None of the these

Show Answer Workspace

3) Study the following program:

1. int1 = 10
2. int2 = 6
3. if int != int2:
4. int2 = ++int2
5. print(int1 - int2)

What will be the output of this program?

a. 2
b. 4
c. 6
d. None

Show Answer Workspace

4) Study the following program:


1. int1 = 10
2. int2 = 6
3. if int != int2:
4. int2 = ++int1
5. print(int1 - int2)

What will be the output of this program?

a. 2
b. 4
c. 0
d. No Output

Show Answer Workspace

5) Study the following program:

1. print(6 + 5 - 4 * 3 / 2 % 1)

What will be the output of this program?

a. 7
b. 7.0
c. 15
d. 0

Show Answer Workspace

6) Study the following program:

1. int1 = 0b0010
2. print(int1)

What will be the output of this program?

a. 0b0010
b. 2
c. NameError: name '0b0010' is not defined
d. SyntaxError

Show Answer Workspace

7) Study the following program:

1. word = "javatpoint"
2. print(*word)

What will be the output of this program?

a. javatpoint
b. j a v a t p o i n t
c. *word
d. SyntaxError: invalid syntax

Show Answer Workspace

8) Study the following program:

1. i = 2, 10
2. j = 3, 5
3. add = i + j
4. print(add)

What will be the output of this program?

a. (5, 10)
b. 20
c. (2, 10, 3, 5)
d. SyntaxError: invalid syntax

Show Answer Workspace


9) Study the following program:

1. print(int(6 == 6.0) * 3 + 4 % 5)

What will be the output of this program?

a. 22
b. 18
c. 20
d. 7

Show Answer Workspace

10) Study the following program:

1. i = 2
2. j = 3, 5
3. add = i + j
4. print(add)

What will be the output of this program?

a. 5, 5
b. 5
c. (2 , 3 , 5)
d. TypeError

Show Answer Workspace

11) How many control statements python supports?

a. Four
b. Five
c. Three
d. None of the these

Show Answer Workspace

12) How many keywords present in the python programming language?

a. 32
b. 61
c. 33
d. 27

Show Answer Workspace

13) Which of the following arithmetic operators cannot be used with strings in python?

a. +
b. *
c. -
d. All of the mentioned

Show Answer Workspace

14) Study the following program:

1. print("java", 'point', sep='2')

What will be the output of this program?

a. javapoint2
b. japoint
c. java2point
d. javapoin2

Show Answer Workspace


15) Study the following program:

1. print('It\'s ok, don\'t worry')

What will be the output of this program?

a. It's ok, don't worry


b. It\'s ok, don\'t worry
c. SyntaxError: EOL while scanning string literal
d. SyntaxError: invalid syntax

Show Answer Workspace

16) Study the following program:

1. _ = '1 2 3 4 5 6'
2. print(_)

What will be the output of this program?

a. SyntaxError: EOL while scanning string literal


b. SyntaxError: invalid syntax
c. NameError: name '_' is not defined
d. 1 2 3 4 5 6

Show Answer Workspace

17) Which of the following keywords is not reversed keyword in python?

a. None
b. class
c. goto
d. and

Show Answer Workspace


18) Study the following program:

1. a = '1 2'
2. print(a * 2)
3. print(a * 0)
4. print(a * -2)

What will be the output of this program?

a. 1212
b. 2 4
c. 0
d. -1 -2 -1 -2

Show Answer Workspace

19) Study the following program:

1. print(max("zoo 145 com"))

What will be the output of this program?

a. 145
b. 122
c. a
d. z

Show Answer Workspace

20) Study the following program:

1. a = "123789"
2. while x in a:
3. print(x, end=" ")

What will be the output of this program?


a. iiiiii…
b. 123789
c. SyntaxError
d. NameError

Show Answer Workspace

21) PVM is often called _________.

a. Python interpreter
b. Python compiler
c. Python volatile machine
d. Portable virtual machine

Show Answer Workspace

22) Study the following program:

1. i = {4, 5, 6}
2. i.update({2, 3, 4})
3. print(i)

What will be the output of this program?

a. 234456
b. 2 3 4 5 6
c. 4 5 6 2 3 4
d. Error, duplicate element presents in list

Show Answer Workspace

23) Study the following program:

1. i=(12, 20, 1, 0, 25)


2. i.sort()
3. print(i)

What will be the output of this program?

a. 0 1 12 20 25
b. 1 12 20 25
c. FunctionError
d. AttributeError

Show Answer Workspace

24) Which of the following keywords is used for function declaration in Python language?

a. def
b. function_name
c. define
d. None of the these

Show Answer Workspace

25) Which of the following objects are present in the function header in python?

a. Function name and Parameters


b. Only function name
c. Only parameters
d. None of the these

Show Answer Workspace

26) When a user does not use the return statement inside a function in Python, what will
return the function in that case.

a. 0
b. 1
c. None
d. No output

Show Answer Workspace

27) Which one of the following is the right way to call a function?

a. call function_name()
b. function function_name()
c. function_name()
d. None of the these

Show Answer Workspace

28) Suppose a user wants to print the second value of an array, which has 5 elements. What
will be the syntax of the second value of the array?

a. array[2]
b. array[1]
c. array[-1]
d. array[-2]

Show Answer Workspace

29) Study the following program:

1. str1="python language"
2. str1.find("p")
3. print(str1)

What will be the output of this program?

a. Print the index value of the p.


b. p
c. python language
d. AttributeError

Show Answer Workspace

30) Study the following program:

1. flag = ""
2. a = 0
3. i = 1
4. while(a < 3):
5. j=1
6. if flag:
7. i=j*i+5
8. else:
9. i=j*i+1
10. a=a+1
11. print(i)

What will be the output of this program?

a. 12
b. 4
c. 11
d. 16

Show Answer Workspace

31) Study the following expression:

1. str = [(1, 1), (2, 2), (3, 3)]

What type of data is in this expression?

a. String type
b. Array lists
c. List of tuples
d. str lists

Show Answer Workspace

32) Which of the following statements is not valid regarding the variable in python?

a. The variable_name can begin with alphabets


b. The variable_name can begin with an underscore
c. The variable_name can begin with a number
d. None of the these

Show Answer Workspace

33) Study the following program:

1. a = 2
2. while(a > -100):
3. a=a-1
4. print(a)

How many times will this program run the loop?

a. Infinite
b. 102
c. 2
d. 1

Show Answer Workspace

34) Study the following program:

1. arr = [3 , 2 , 5 , 6 , 0 , 7, 9]
2. add1 = 0
3. add2 = 0
4. for elem in arr:
5. if (elem % 1 == 0):
6. add1 = add1 + elem
7. continue
8. if (elem % 3 == 0):
9. add2 = add2 + elem
10. print(add1 , end=" ")
11. print(add2)

What will be the output of this program?

a. 32 0
b. 0 32
c. 18 0
d. 0 18

Show Answer Workspace

35) Which of the following statements is valid for "if statement"?

a. if f >= 12:
b. if (f >= 122)
c. if (f => 1222)
d. if f >= 12222

Show Answer Workspace

36) Which of the following blocks allows you to test the code blocks for errors?

a. except block
b. try block
c. finally block
d. None of the these
Show Answer Workspace

37) Study the following program:

1. try:
2. print(file_name)
3. except:
4. print("error comes in the line")

What will be the output of this program?

a. file_name
b. error
c. error comes in the line
d. file_name error comes in the line

Show Answer Workspace

38) Study the following program:

1. i = 10
2. j = 8
3. assert i > j, 'j = i + j'
4. print(j)

What will be the output of this program?

a. 18
b. 8
c. No output
d. TypeError

Show Answer Workspace

39) Study the following program:


1. class Student:
2. print("Students of Section A")
3. Student()
4. Student()
5. obj = Student()

How many objects are there for the given program?

a. 1
b. 2
c. 3
d. None of the these

Show Answer Workspace

40) Study the following program:

1. class Teacher:
2. def __init__(name, id_no, age):
3. name.id_no = id_no
4. name.age = age
5. teac = Teacher(5, 25)

Which of the following statements is incorrect regarding this program?

a. A constructor has been given in this program


b. id_no and age are called the parameters
c. The "teac" is the reference variable for the object Teacher(5, 25)
d. None of the these

Show Answer Workspace

41) Study the following program:

1. class Teacher:
2. def __init__(self, id, age):
3. self.id = id
4. self.age = age
5. print(self.age)
6. tear = Teacher("John", 20)
7. tear.age = 30
8. print(tear.age)

Which of the following statements is incorrect regarding this program?

a. 20 John 30
b. 20 30
c. John 30
d. 30 John 20

Show Answer Workspace

42) Which of the following code will create a set in python language?

1. thisset = (("apple", "banana", "cherry"))

2. thisset = ("car", "bike", "123")

3. thisset = {}

a. 1 only
b. 1 and 2 both
c. 1, 2, and 3 will create a set
d. None of the these

Show Answer Workspace

43) Study the following program:

1. set = {0, 0, "a1", 0, 9}


2. print(set)
What will be the output of this program?

a. {0, 0, 'a1', 0, 9}
b. {0, 'a1', 0, 9}
c. {0, 9, 'a1'}
d. {0, 0, 9, 0, 'a1'}

Show Answer Workspace

44) Which of the following statements would create a tuple in python?

a. mytuple = ("apple", "banana", "cherry")


b. mytuple[123] = ("apple", "banana", "cherry")
c. mytuple = ("2" * ("apple", "banana", "cherry"))
d. None of the these

Show Answer Workspace

45) Study the following program:

1. mytuple1=(5, 1, 7, 6, 2)
2. mytuple1.pop(2)
3. print(mytuple1)

What will be the output of this program?

a. 51762
b. No output
c. AttributeError
d. None of the these

Show Answer Workspace

46) Which of the following functions returns a list containing all matches?
a. find
b. findall
c. search
d. None of the these

Show Answer Workspace

47) Study the following program:

1. mytuple1 = (2, 4, 3)
2. mytuple3 = mytuple1 * 2
3. print(mytuple3)

What will be the output of this program?

a. (2, 4, 3, 2, 4, 3)
b. (2, 2, 4, 4, 3, 3)
c. (4, 8, 6)
d. Error

Show Answer Workspace

48) In the Python Programming Language, syntax error is detected by ______ at _________.

a. Interpreter / Compile time


b. Run time / Interpreter
c. Interpreter / Run time
d. Compile time / Run time

Show Answer Workspace

49) Study the following program:

1. i = [10, 11, 12, 13]


2. for i[-2] in i:
3. print(i[-2])

What will be the output of this program?

a. 10 11 11 12
b. 10 11 11 13
c. 10 8 6 4
d. SyntaxError

Show Answer Workspace

50) Which of the following blocks allows you to handle the errors?

a. except block
b. try block
c. finally block
d. None of the these

1. Python is a ___object-oriented programming language.

A. Special purpose
B. General purpose
C. Medium level programming language
D. All of the mentioned above

Answer: B) General purpose

Explanation:

As a General Purpose Object-Oriented Programming Language, Python can


model real-world entities, which makes it a useful tool for data scientists. Because
it performs type checking at runtime, it is also known as dynamically typed code.
Python is a general-purpose programming language, which means that it is
widely used in every domain. This is due to the fact that it is very simple to
understand and scalable, which allows for rapid development.

Discuss this Question

2. Amongst the following, who is the developer of Python programming?

A. Guido van Rossum


B. Denis Ritchie
C. Y.C. Khenderakar
D. None of the mentioned above

Answer: A) Guido van Rossum

Explanation:

Python programming was created by Guido van Rossum. It is also called general-
purpose programming language.

Discuss this Question

3. Amongst which of the following is / are the application areas of Python


programming?

A. Web Development
B. Game Development
C. Artificial Intelligence and Machine Learning
D. All of the mentioned above

Answer: D) All of the mentioned above

Explanation:

Python programming is used in a variety of fields, including web development,


game development, artificial intelligence, and machine learning, among others.
Web Development - Python provides a number of web development frameworks,
including Django, Pyramid, and Flask, among others. Security, flexibility, and
scalability are all attributes of this framework. Development of Video Games -
PySoy and PyGame are two Python libraries that are used in the development of
video games. Artificial Intelligence and Machine Learning - There are a large
number of open-source libraries that can be used when developing AI/ML
applications, and many of these libraries are free.

Discuss this Question

4. Amongst which of the following is / are the Numeric Types of Data


Types?

A. int
B. float
C. complex
D. All of the mentioned above

Answer: D) All of the mentioned above

Explanation:

Numeric data types include int, float, and complex, among others. In information
technology, data types are the classification or categorization of knowledge
items. It represents the type of information that is useful in determining what
operations are frequently performed on specific data. In the Python
programming language, each value is represented by a different python data
type. Known as Data Types, this is the classification of knowledge items or the
placement of the information value into a specific data category. It is beneficial to
be aware of the quiet operations that are frequently performed on a worth.

Discuss this Question

5. list, tuple, and range are the ___ of Data Types.

A. Sequence Types
B. Binary Types
C. Boolean Types
D. None of the mentioned above

Answer: A) Sequence Types

Explanation:

The sequence Types of Data Types are the list, the tuple, and the range. In order
to store multiple values in an organized and efficient manner, we use the concept
of sequences. There are several types of sequences, including strings, Unicode
strings, lists, tuples, bytearrays, and range objects. Strings and Unicode strings are
the most common. Dictionary and set data structures are used to store non-
sequential information.

Discuss this Question

ADVERTISEMENT

6. Float type of data type is represented by the float class.

A. True
B. False

Answer: A) True

Explanation:

The float data type is represented by the float class of data types. A true number
with a floating-point representation is represented by the symbol. It is denoted
by the use of a decimal point. Optionally, the character e or E followed by a
positive or negative integer could be appended to the end of the string to
indicate scientific notation.

Discuss this Question

7. bytes, bytearray, memoryview are type of the ___ data type.


A. Mapping Type
B. Boolean Type
C. Binary Types
D. None of the mentioned above

Answer: C) Binary Types

Explanation:

The Binary type's data type is represented by the bytes, byte array, and memory
view types. Binary data manipulation is accomplished through the use of bytes
and byte array. The memory view makes use of the buffer protocol in order to
access the memory of other binary objects without the need to make a copy of
the data. Bytes objects are immutable sequences of single bytes that can only be
changed. When working with ASCII compatible data, we should only use them
when necessary.

Discuss this Question

8. The type() function can be used to get the data type of any object.

A. True
B. False

Answer: A) True

Explanation:

The type() function can be used to find out what type of data an object contains.
Typing an object passed as an argument to Python's type() function returns the
data type of the object passed as an argument to Python's type() function. This
function is extremely useful during the debugging phase of the process.

Discuss this Question

9. Binary data type is a fixed-width string of length bytes?


A. True
B. False

Answer: A) True

Explanation:

It is a fixed-width string of length bytes, where the length bytes is declared as an


optional specifier to the type, and its width is declared as an integer. If the length
is not specified, the default value is 1. When necessary, values are right-extended
to fill the entire width of the column by using the zero byte as the first byte.

Discuss this Question

10. Varbinary data type returns variable-width string up to a length of max-


length bytes?

A. TRUE
B. FALSE

Answer: A) TRUE

Explanation:

Varbinary - a variable-width string with a length of max-length bytes, where the


maximum number of bytes is declared as an optional specifier to the type, and
where the maximum number of bytes is declared as an optional specifier to the
type. The default attribute size is 80 bytes, and the maximum length is 65000
bytes. The default attribute size is 80 bytes. The range of binary values is not
extended to fill the entire width of the column.

Discuss this Question

ADVERTISEMENT

11. Amongst which of the following is / are the logical operators in Python?
A. and
B. or
C. not
D. All of the mentioned above

Answer: D) All of the mentioned above

Explanation:

Python's logical operators are represented by the terms and, or, and not. In
Python, logical operators are used to perform logical operations on the values of
variables that have been declared. Either true or false is represented by the value.
The truth values provide us with the information we need to figure out the
conditions. In Python, there are three types of logical operators: the logical AND,
the logical OR, and the logical NOT operators. Keywords or special characters are
used to represent operators in a program.

Discuss this Question

12. Is Python supports exception handling?

A. Yes
B. No

Answer: A) Yes

Explanation:

Unexpected events that can occur during a program's execution are referred to
as exceptions, and they can cause the program's normal flow to be interrupted.
Python provides exception handling, which allows us to write less error-prone
code while also testing various scenarios that may result in an exception later on
in the process.

Discuss this Question


13. What is the name of the operator ** in Python?

A. Exponentiation
B. Modulus
C. Floor division
D. None of the mentioned above

Answer: A) Exponentiation

Explanation:

The ** is an exponentiation operator in the Python programming language. In


Python, the ** operator is used to raise the number on the left to the power of
the exponent on the right, which is represented by the symbol **. In other words,
in the expression 2 ** 3, 2 is raised to the third power, which is a positive number.
In mathematics, we frequently see this expression written as 23, but what is really
happening is that the numbers 2 and 3 are being multiplied by themselves three
times. In Python, we would get the same result of 8 by running either 2 ** 3 or 2 *
2 * 2.

Discuss this Question

14. The % operator returns the ___.

A. Quotient
B. Divisor
C. Remainder
D. None of the mentioned above

Answer: C) Remainder

Explanation:

The % operator (it is an arithmetic operator) returns the amount that was left
over. This is useful for determining the number of times a given number is
multiplied by itself.

Discuss this Question


15. Amongst which of the following is / are the method of list?

A. append()
B. extend()
C. insert()
D. All of the mentioned above

Answer: D) All of the mentioned above

Explanation:

list.append(x), list.extend(iterable), list.insert(i, x) are the methods of


list. list.append(x) - add an item to the end of the
list. list.extend(iterable) - extend the list by appending all the items from the
iterable. list.insert(i, x) Insert an item at a given position.

Discuss this Question

ADVERTISEMENT

16. The list.pop ([i]) removes the item at the given position in the list?

A. True
B. False

Answer: A) True

Explanation:

The external is not a valid variable scope in PHP.

Discuss this Question

17. The list.index(x[, start[, end]]) is used to ___.


A. Return zero-based index in the list
B. Raises a ValueError if there is no such item
C. Both A and B
D. None of the mentioned above

Answer: C) Both A and B

Explanation:

The index(x[, start[, end]]) is used to return the zero-based index in the list of the
first item whose value is equal to x. index() is used to return the zero-based index
in the list of the first item whose value is equal to x. If there is no such item, the
method raises a ValueError. The optional arguments start and end are interpreted
in the same way as in the slice notation and are used to restrict the search to a
specific subsequence of the list of elements. Instead of using the start argument
to calculate the index, the returned index is computed relative to the beginning
of the full sequence.

Discuss this Question

18. Python Dictionary is used to store the data in a ___ format.

A. Key value pair


B. Group value pair
C. Select value pair
D. None of the mentioned above

Answer: A) Key value pair

Explanation:

Python Dictionary is used to store the data in a key-value pair format, which is
similar to that of a database. The dictionary data type in Python is capable of
simulating the real-world data arrangement in which a specific value exists for a
specific key when the key is specified. It is the data-structure that can be
changed. Each element of the dictionary is defined as follows: keys and values.

Discuss this Question


19. The following is used to define a ___.

d = {
<key>: <value>,
<key>: <value>,
.
.
.
<key>: <value>
}

A. Group
B. List
C. Dictionary
D. All of the mentioned above

Answer: C) Dictionary

Explanation:

With the help of curly braces (), we can define a dictionary that contains a list of
key-value pairs that are separated by commas. Each key and its associated value
are separated by a colon (:). For example:

d = {
<key>: <value>,
<key>: <value>,
.
.
.
<key>: <value>
}

Discuss this Question

20. Python Literals is used to define the data that is given in a variable or
constant?
A. True
B. False

Answer: A) True

Explanation:

It is possible to define literals in Python as data that is provided in a variable or


constant. Literal collections are supported in Python as well as String and
Numeric literals, Boolean and Boolean expressions, Special literals, and Special
expressions.

Discuss this Question

ADVERTISEMENT

21. Conditional statements are also known as ___ statements.

A. Decision-making
B. Array
C. List
D. None of the mentioned above

Answer: A) Decision-making

Explanation:

Conditional statements, also known as decision-making statements, are used to


make decisions. In programming, we want to be able to control the flow of
execution of our program, and we want to be able to execute a specific set of
statements only if a specific condition is met, and a different set of statements
only if the condition is not met. As a result, we use conditional statements to
determine whether or not a specific block of code should be executed based on a
given condition.

Discuss this Question


22. The if statement is the most fundamental decision-making statement?

A. True
B. False

Answer: A) True

Explanation:

The if statement is the most fundamental decision-making statement, and it


determines whether or not the code should be executed based on whether or not
the condition is met. If the condition in the if statement is met, a code body is
executed, and the code body is not otherwise executed. The statement can be as
simple as a single line of code or as complex as a block of code.

Discuss this Question

23. Amongst which of the following if syntax is true?

A. if condition:
B. #Will executes this block if the condition is true
C.
D. if condition
E. {
F. #Will executes this block if the condition is true
G. }
H.
I. if(condition)
J. #Will executes this block if the condition is true
K.
L. None of the mentioned above

Answer: A)

if condition:
#Will executes this block if the condition is true

Explanation:
If is a keyword which works with specified condition. If statement in Python has
the subsequent syntax:

if condition:
#Will executes this block if the condition is true

Discuss this Question

24. Amongst which of the following is / are the conditional statement in


Python code?

A. if a<=100:
B. if (a >= 10)
C. if (a => 200)
D. None of the mentioned above

Answer: A) if a<=100:

Explanation:

The if statement in Python is used to make decisions in various situations. It


contains a body of code that is only executed when the condition specified in the
if statement is true; if the condition is not met, the optional else statement is
executed, which contains code that is executed when the else condition is met.

Discuss this Question

25. Which of the following is not used as conditional statement in Python?

A. switch
B. if...else
C. elif
D. None of the mentioned above

Answer: A) switch
Explanation:

Python does not have a switch or case statement like other programming
languages. Because Python lacks switch statement functionality in comparison to
other programming languages, it is not recommended for beginners. As a result,
we use other alternatives that can replace the functionality of the switch case
statement and make programming easier and faster. We employ dictionary
mapping to get around this limitation.

Discuss this Question

26. Which of the following is false regarding conditional statement in


Python?

A. If-elif is the shortcut for the if-else chain


B. We use the dictionary to replace the Switch case statement
C. We cannot use python classes to implement the switch case statement
D. None of the mentioned above

Answer: C) We cannot use python classes to implement the switch case


statement

Explanation:

It is possible to shorten the if-else chain by using the if-elif construct. Use the if-
elif statement and include an else statement at the end, which will be executed if
none of the if-elif statements in the previous section are true. As a replacement
for the Switch case statement, we use the dictionary data type, whose key values
function similarly to those of the cases in a switch statement. When implementing
the switch case statement in Python, we can make use of Python classes. A class
is a type of object function Object() { [native code] } that can be extended with
properties and methods. So, let's look at an example of how to perform a switch
case using a class by creating a switch method within the Python switch class and
then calling it.

Discuss this Question


27. In Python, an else statement comes right after the block after 'if'?

A. True
B. False

Answer: A) True

Explanation:

After the 'if' condition, an else statement is placed immediately after the block. if-
else statements are used in programming in the same way that they are used in
the English language. The following is the syntax for the if-else statement:

if(condition):
Indented statement block for when condition is TRUE
else:
Indented statement block for when condition is FALSE

Discuss this Question

28. In a Python program, Nested if Statements denotes?

A. if statement inside another if statement


B. if statement outside the another if statement
C. Both A and B
D. None of the mentioned above

Answer: A) if statement inside another if statement

Explanation:

Nesting an if statement within another if statement is referred to as nesting in the


programming community. It is not always necessary to use a simple if statement;
instead, you can combine the concepts of if, if-else, and even if-elif-else
statements to create a more complex structure.

Discuss this Question


29. What will be the output of the following Python code?

a=7
if a>4: print("Greater")

A. Greater
B. 7
C. 4
D. None of the mentioned above

Answer: A) Greater

Explanation:

When only one statement needs to be executed within an if block, the short hand
if statement is used to accomplish this. This statement can be included in the
same line as the if statement, if necessary. When using Python's Short Hand if
statement, the following syntax is used:

if condition: statement

Discuss this Question

30. What will be the output of the following Python code?

x,y = 12,14

if(x+y==26):
print("true")
else:
print("false")

A. true
B. false

Answer: A) true
Explanation:

In this code the value of x = 12 and y = 14, when we add x and y the value will be
26 so x+y= =26. Hence, the given condition will be true.

Discuss this Question

ADVERTISEMENT

31. What will be the output of the following Python code?

x=13

if x>12 or x<15 and x==16:


print("Given condition matched")
else:
print("Given condition did not match")

A. Given condition matched


B. Given condition did not match
C. Both A and B
D. None of the mentioned above

Answer: A) Given condition matched

Explanation:

In this code the value of x = 13, and the condition 13>12 or 13<15 is true but
13==16 becomes falls. So, the if part will not execute and program control will
switch to the else part of the program and output will be "Given condition did
not match".

Discuss this Question

32. Consider the following code segment and identify what will be the
output of given Python code?
a = int(input("Enter an integer: "))
b = int(input("Enter an integer: "))

if a <= 0:
b = b +1
else:
a = a + 1

A. if inputted number is a negative integer then b = b +1


B. if inputted number is a positive integer then a = a +1
C. Both A and B
D. None of the mentioned above

Answer: C) Both A and B

Explanation:

In above code, if inputted number is a negative integer, then b = b +1 and if


inputted number is a positive integer, then a = a +1. Hence, the output will be
depending on inputted number.

Discuss this Question

33. In Python, ___ defines a block of statements.

A. Block
B. Loop
C. Indentation
D. None of the mentioned above

Answer: C) Indentation

Explanation:

Python's concept of indentation is extremely important because, if the Python


code is not properly indented, we will encounter an Indentation Error and the
code will not be able to be successfully compiled. In Python, to indicate a block of
code, we must indent each line of the block by the same amount on each line of
the block. As a result, indentation denotes the beginning of a block of
statements.

Discuss this Question

34. An ___ statement has less number of conditional checks than two
successive ifs.

A. if else if
B. if elif
C. if-else
D. None of the mentioned above

Answer: C) if-else

Explanation:

A single if-else statement requires fewer conditional checks than two


consecutives if statements. If the condition is true, the if-else statement is used to
execute both the true and false parts of the condition in question. The condition
is met, and therefore the if block code is executed, and if the condition is not
met, the otherwise block code is executed.

Discuss this Question

35. In Python, the break and continue statements, together are called ___
statement.

A. Jump
B. goto
C. compound
D. None of the mentioned above

Answer: B) goto

Explanation:
With the goto statement in Python, we are basically telling the interpreter to skip
over the current line of code and directly execute another one instead of the
current line of code. You must place a check mark next to the line of code that
you want the interpreter to execute at this time in the section labelled "target."

Discuss this Question

36. What will be the output of the following Python code?

num = 10

if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")

A. Positive number
B. Negative number
C. Real number
D. None of the mentioned above

Answer: A) Positive number

Explanation:

In this case, the If condition is evaluated first and then the else condition. If it is
true, the elif statement will be executed. If it is false, nothing will happen. elif is an
abbreviation for else if. It enables us to check for multiple expressions at the
same time. Similarly, if the condition for if is False, the condition for the next elif
block is checked, and so on. If all of the conditions are met, the body of the else
statement is run.

Discuss this Question

37. The elif statement allows us to check multiple expressions.


A. True
B. False

Answer: A) True

Explanation:

It is possible to check multiple expressions for TRUE and to execute a block of


code as soon as one of the conditions evaluates to TRUE using the elif statement.
The elif statement is optional in the same way that the else statement is. The
difference between elif and else is that, unlike else, where there can only be one
statement, elif statements can be followed by an arbitrary number of statements.

Discuss this Question

38. What will be the output of the following Python code?

i=5
if i>11 : print ("i is greater than 11")

A. No output
B. Abnormal termination of program
C. Both A and B
D. None of the mentioned above

Answer: C) Both A and B

Explanation:

In the above code, the assign value of i = 5 and as mentioned in the condition if
5 > 11: print ("i is greater than 11"), here 5 is not greater than 11 so condition
becomes false and there will not be any output and program will be abnormally
terminated.

Discuss this Question


39. What will be the output of the following Python code?

a = 13
b = 15
print("A is greater") if a > b else print("=") if a == b else
print("B is greater")

A. A is greater
B. B is greater
C. Both A and B
D. None of the mentioned above

Answer: B) B is greater

Explanation:

In the above code, the assign value for a = 13 and b = 15. There are three
conditions mentioned in the code,

1. print("A is greater") if a > b , here 13 is not greater than 15 so condition


becomes false
2. print("=") if a == b , here 13 is not equal to 15 so condition becomes false
3. else print("B is greater"), condition 1 and 2 will not be true so program
control will switch to else part and output will be "B is greater".

Discuss this Question

40. If a condition is true the not operator is used to reverse the logical state?

A. True
B. False

Answer: A) True

Explanation:

In order to make an if statement test whether or not something occurred, we


must place the word not in front of our condition. When the not operator is used
before something that is false, it returns true as a result. And when something
that is true comes before something that is false, we get False. That is how we
determine whether or not something did not occur as claimed. In other words,
the truth value of not is the inverse of the truth value of yes. So, while it may not
appear to be abstract, this operator simply returns the inverse of the Boolean
value.

Discuss this Question

41. Loops are known as ___ in programming.

A. Control flow statements


B. Conditional statements
C. Data structure statements
D. None of the mentioned above

Answer: A) Control flow statements

Explanation:

The control flow of a program refers to the sequence in which the program's
code is executed. Conditional statements, loops, and function calls all play a role
in controlling the flow of a Python program's execution.

Discuss this Question

42. The for loop in Python is used to ___ over a sequence or other iterable
objects.

A. Jump
B. Iterate
C. Switch
D. All of the mentioned above

Answer: B) Iterate
Explanation:

It is possible to iterate over a sequence or other iterable objects using the for
loop in Python. The process of iterating over a sequence is referred to as
traversal. Following syntax can be follow to use for loop in Python Program –

for val in sequence:


...
loop body
...

For loop does not require an indexing variable to set beforehand.

Discuss this Question

43. With the break statement we can stop the loop before it has looped
through all the items?

A. True
B. False

Answer: A) True

Explanation:

In Python, the word break refers to a loop control statement. It serves to control
the sequence of events within the loop. If you want to end a loop and move on to
the next code after the loop; the break command can be used to do so. When an
external condition causes the loop to terminate, it represents the common
scenario in which the break function is used in Python.

Discuss this Question

44. The continue keyword is used to ___ the current iteration in a loop.

A. Initiate
B. Start
C. End
D. None of the mentioned above

Answer: C) End

Explanation:

The continue keyword is used to terminate the current iteration of a for loop (or a
while loop) and proceed to the next iteration of the for loop (or while loop). With
the continue statement, you have the option of skipping over the portion of a
loop where an external condition is triggered, but continuing on to complete the
remainder of the loop. As a result, the current iteration of the loop will be
interrupted, but the program will continue to the beginning of the loop. The
continue statement will be found within the block of code that is contained
within the loop statement, and is typically found after a conditional if statement.

Discuss this Question

45. Amongst which of the following is / are true about the while loop?

A. It continually executes the statements as long as the given condition is true


B. It first checks the condition and then jumps into the instructions
C. The loop stops running when the condition becomes fail, and control will
move to the next line of code.
D. All of the mentioned above

Answer: D) All of the mentioned above

Explanation:

While loops are used to execute statements repeatedly as long as the condition is
met, they are also used to execute statements once. It begins by determining the
condition and then proceeds to execute the instructions. Within the while loop,
we can include any number of statements that we want. The condition can be
anything we want it to be depending on our needs. When the condition fails, the
loop comes to an end, and the execution moves on to the next line of code in the
program.
Discuss this Question

46. The ___ is a built-in function that returns a range object that consists
series of integer numbers, which we can iterate using a for loop.

A. range()
B. set()
C. dictionary{}
D. None of the mentioned above

Answer: A) range()

Explanation:

This type represents an immutable sequence of numbers and is commonly used


in for loops to repeat a specific number of times a given sequence of numbers.
The range() function in Python generates an immutable sequence of numbers
beginning with the given start integer and ending with the given stop integer. For
loops, we can use the range() built-in function to return an object that contains a
series of integer numbers, which we can then iterate through using a for loop.

Discuss this Question

47. What will be the output of the following Python code?

for i in range(6):
print(i)

A. 0
1
2
3
4
5
B. 0
1
2
3
C. 1
2
3
4
5
D. None of the mentioned above

Answer: A)
0
1
2
3
4
5

Explanation:

The range(6) is define as function. Loop will print the number from 0.

Discuss this Question

48. The looping reduces the complexity of the problems to the ease of the
problems?

A. True
B. False

Answer: A) True

Explanation:
The looping simplifies the complex problems into the easy ones. It enables us to
alter the flow of the program so that instead of writing the same code again and
again, we can repeat the same code for a finite number of times.

Discuss this Question

49. The while loop is intended to be used in situations where we do not


know how many iterations will be required in advance?

A. True
B. False

Answer: A) True

Explanation:

The while loop is intended to be used in situations where we do not know how
many iterations will be required in advance. When a while loop is used, the block
of statements within it is executed until the condition specified within the while
loop is satisfied. It is referred to as a pre-tested loop in some circles.

Discuss this Question

50. Amongst which of the following is / are true with reference to loops in
Python?

A. It allows for code reusability to be achieved.


B. By utilizing loops, we avoid having to write the same code over and over
again.
C. We can traverse through the elements of data structures by utilizing
looping.
D. All of the mentioned above

Answer: D) All of the mentioned above

Explanation:
Following point's shows the importance of loops in Python.

• It allows for code reusability to be achieved.


• By utilizing loops, we avoid having to write the same code over and over
again.
• We can traverse through the elements of data structures by utilizing
looping.

Discuss this Question

51. A function is a group of related statements which designed specifically


to perform a ___.

A. Write code
B. Specific task
C. Create executable file
D. None of the mentioned above

Answer: B) Specific task

Explanation:

A function is a group of related statements designed specifically to perform a


specific task. Functions make programming easier to decompose a large problem
into smaller parts. The function allows programmers to develop an application in
a modular way. As our program grows larger and larger, functions make it more
organized and manageable.

Discuss this Question

52. Amongst which of the following is a proper syntax to create a function


in Python?

A. def function_name(parameters):
B. ...
C. Statements
D. ...
E.
F. def function function_name:
G. ...
H. Statements
I. ...
J.
K. def function function_name(parameters):
L. ...
M. Statements
N. ...
O.
P. None of the mentioned above

Answer: A)

def function_name(parameters):
...
Statements
...

Explanation:

To define a function we follow the syntax mentioned in the answer section. def
keyword marks the start of the function header. We start from the def keyword
and write the name of the function along with function parameters. Function
naming follows the naming rules to write identifiers in Python. Arguments or
parameters are passed as function arguments. Function arguments are optional.
A colon (:) denotes the end of the function header.

def function_name(parameters):
...
Statements
...

Discuss this Question

53. Once we have defined a function, we can call it?


A. True
B. False

Answer: A) True

Explanation:

Once a function has been defined, it can be called from another function, a
program, or even from the Python prompt itself. To call a function, we simply
type the name of the function followed by the appropriate parameters into the
command line.

For example-

def user_name(name):
# This function greets to user
# to put name
print("Hello, " + name + ".")

user_name("Amit") # Amit passed as function argument

# Output: Hello, Amit.

Discuss this Question

54. Amongst which of the following shows the types of function calls in
Python?

A. Call by value
B. Call by reference
C. Both A and B
D. None of the mentioned above

Answer: C) Both A and B

Explanation:

Call by value and Call by reference are the types of function calls in Python.
• Call by value - When, we call a function with the values i.e. to pass the
variables (not their references), the values of the passing arguments cannot
be changed inside the function.
• Call by reference - When, we call a function with the reference/object, the
values of the passing arguments can be changed inside the function.

Discuss this Question

55. What will be the output of the following Python code?

def show(id,name):
print("Your id is :",id,"and your name is :",name)

show(12,"deepak")

A. Your id is: 12 and your name is: deepak


B. Your id is: 11 and your name is: Deepak
C. Your id is: 13 and your name is: Deepak
D. None of the mentioned above

Answer: A) Your id is: 12 and your name is: deepak

Explanation:

If we define a function in Python with parameters, and at the time of calling


function it requires parameters. In above code passing arguments are 12, and
Deepak. So, Output will be Your id is: 12 and your name is: deepak

Discuss this Question

56. Amongst which of the following is a function which does not have any
name?

A. Del function
B. Show function
C. Lambda function
D. None of the mentioned above

Answer: C) Lambda function

Explanation:

Lambda function is an anonymous function, which means that it does not have a
name, as opposed to other functions. Unlike other programming languages,
Python allows us to declare functions without using the def keyword, which is
what we would normally do to declare a function. As an alternative, the lambda
keyword is used to declare the anonymous functions that will be used
throughout the program. When compared to other functions, lambda functions
can accept any number of arguments, but they can only return a single value,
which is represented by an expression.

Syntax:

lambda arguments: expression

Discuss this Question

57. Can we pass List as an argument in Python function?

A. Yes
B. No

Answer: A) Yes

Explanation:

In a function, we can pass any data type as an argument, such as a string or a


number or a list or a dictionary, and it will be treated as if it were of that data
type inside the function. The following code exemplifies this –

def St_list(student):
for x in student:
print(x)
students = ["Anil", "Rex", "Jerry"]
St_list(students)

"""
Output:
Anil
Rex
Jerry
"""

Discuss this Question

58. A method refers to a function which is part of a class?

A. True
B. False

Answer: A) True

Explanation:

A method is a function that is a part of a class that has been defined. It is


accessed through the use of an instance or object of the class. A function, on the
other hand, is not restricted in this way: it simply refers to a standalone function.
This implies that all methods are functions, but that not all functions are methods
in the same sense.

Discuss this Question

59. The return statement is used to exit a function?

A. True
B. False

Answer: A) True

Explanation:
The return statement is used to exit a function and go back to the place from
where it was called.

Syntax of return:

return [expression_list]

In this statement, you can include an expression that will be evaluated and the
resulting value will be returned. A function will return the None object if there is
no expression in the statement or if the return statement itself is not present
within a function's body.

Discuss this Question

60. Scope and lifetime of a variable declared in a function exist till the
function exists?

A. True
B. False

Answer: A) True

Explanation:

It is the portion of a program where a variable is recognized that is referred to as


its scope. It is not possible to see the parameters and variables defined within a
function from outside of the function. As a result, they are limited in their
application. The lifetime of a variable is the period of time during which the
variable is stored in the memory of the computer. The lifetime of variables
contained within a function is equal to the length of time the function is in
operation. When we return from the function, they are completely destroyed. As
a result, a function does not retain the value of a variable from previous calls to
the function.

Discuss this Question


61. File handling in Python refers the feature for reading data from the file
and writing data into a file?

A. True
B. False

Answer: A) True

Explanation:

File handling is the capability of reading data from and writing it into a file in
Python. Python includes functions for creating and manipulating files, whether
they are flat files or text documents. We will not need to import any external
libraries in order to perform general IO operations because the IO module is the
default module for accessing files.

Discuss this Question

62. Amongst which of the following is / are the key functions used for file
handling in Python?

A. open() and close()


B. read() and write()
C. append()
D. All of the mentioned above

Answer: D) All of the mentioned above

Explanation:

The key functions used for file handling in Python


are: open(), close(), read(), write(), and append(). the open() function is used to
open an existing file, close() function is used to close a file which opened, read()
function is used when we want to read the contents from an existing file, write()
function is used to write the contents in a file and append() function is used when
we want to append the text or contents to a specific position in an existing file.

Discuss this Question


63. Amongst which of the following is / are needed to open an existing file?

A. filename
B. mode
C. Both A and B
D. None of the mentioned above

Answer: C) Both A and B

Explanation:

In most cases, only the filename and mode parameters are required, with the rest
of the parameters implicitly set to their default values.

Following code demonstrates the example of how to open a file -

f = open ("file.txt")

Discuss this Question

64. Binary files are stored in the form of 0s and 1s?

A. True
B. False

Answer: A) True

Explanation:

Binary files are also stored in terms of bytes (0s and 1s), but, unlike text files,
these bytes do not represent the ASCII values of the characters that are contained
within them. A binary file is a sequence of bytes that is stored in a computer's
memory. Even a single bit change can corrupt a file, rendering it unreadable by
the application that is attempting to read it. In addition, because the binary file's
contents are not human readable, it is difficult to correct any errors that may
occur in the binary file.
Discuss this Question

65. The function file_object.close() is used to ___.

A. To open the existing file


B. To append in an opened file
C. To close an opened file
D. None of the mentioned above

Answer: C) To close an opened file

Explanation:

To close a file that has been opened, use the file object.close() function. To
accomplish this, the Python language provides the close() method. When a file is
closed, the system releases the memory that was allocated to it.

Discuss this Question

66. Python always makes sure that any unwritten or unsaved data is written
to the file before it is closed?

A. True
B. False

Answer: A) True

Explanation:

Whenever a file is closed, Python ensures that any unwritten or unsaved data is
flushed out or written to the file's header before the file is closed. As a result, it is
always recommended that we close the file once our work is completed.
Additionally, if the file object is reassigned to a different file, the previous file is
automatically closed as well.

Discuss this Question


67. The write() method takes a string as an argument and ___.

A. writes it to the text file


B. read from the text file
C. append in a text file
D. None of the mentioned above

Answer: A) writes it to the text file

Explanation:

The write() method accepts a string as an argument and writes it to the text file
specified by the filename parameter. The write() method returns the number of
characters that were written during a single execution of the write() function. A
newline character (n) must also be added at the end of every sentence to indicate
the end of a line.

Discuss this Question

68. The seek() method is used to ___.

A. Saves the file in secondary storage


B. Position the file object at a particular position in a file
C. Deletes the file form secondary storage
D. None of the mentioned above

Answer: B) Position the file object at a particular position in a file

Explanation:

The seek() method is used to position a file object at a specific location within a
file's hierarchy.

Discuss this Question


69. Amongst which of the following function is / are used to create a file
and writing data?

A. append()
B. open()
C. close()
D. None of the mentioned above

Answer: B) open()

Explanation:

To create a text file, we call the open() method and pass it the filename and the
mode parameters to the function. If a file with the same name already exists, the
open() function will behave differently depending on whether the write or
append mode is used to open the file. Write mode (w) will cause all of the
existing contents of the file to be lost, and a new file with the same name will be
created with the same contents as the existing file.

Discuss this Question

70. The readline() is used to read the data line by line from the text file.

A. True
B. False

Answer: A) True

Explanation:

It is necessary to use readline() in order to read the data from a text file line by
line. The lines are displayed by employing the print() command. When the
readline() function reaches the end of the file, it will return an empty string.

Discuss this Question


71. The module Pickle is used to ___.

A. Serializing Python object structure


B. De-serializing Python object structure
C. Both A and B
D. None of the mentioned above

Answer: C) Both A and B

Explanation:

Pickle is a Python module that allows you to save any object structure along with
its associated data. Pickle is a Python module that can be used to serialize and
de-serialize any type of Python object structure. Serialization is the process of
converting data or an object stored in memory to a stream of bytes known as
byte streams, which is a type of data stream. These byte streams, which are
contained within a binary file, can then be stored on a disc, in a database, or
transmitted over a network. Pickling is another term for the serialization process.
De-serialization, also known as unpickling, is the inverse of the pickling process,
in which a byte stream is converted back to a Python object through the pickling
process.

Discuss this Question

72. Amongst which of the following is / are the method of convert Python
objects for writing data in a binary file?

A. set() method
B. dump() method
C. load() method
D. None of the mentioned above

Answer: B) dump() method

Explanation:
The dump() method is used to convert Python objects into binary data that can
be written to a binary file. The file into which the data is to be written must be
opened in binary write mode before the data can be written. To make use of the
dump() method, we can call this function with the parameters data object and file
object. There are two objects in this case: data object and file object. The data
object object is the object that needs to be dumped to the file with the file
handle named file_ object.

Discuss this Question

73. Amongst which of the following is / are the method used to unpickling
data from a binary file?

A. load()
B. set() method
C. dump() method
D. None of the mentioned above

Answer: B) set() method

Explanation:

The load() method is used to unpickle data from a binary file that has been
compressed. The binary read (rb) mode is used to load the file that is to be
loaded. If we want to use the load() method, we can write Store object = load(file
object) in our program. The pickled Python object is loaded from a file with a file
handle named file object and stored in a new file handle named store object. The
pickled Python object is loaded from a file with a file handle named file object
and stored in a new file handle named store object.

Discuss this Question

74. A text file contains only textual information consisting of ___.

A. Alphabets
B. Numbers
C. Special symbols
D. All of the mentioned above

Answer: D) All of the mentioned above

Explanation:

Unlike other types of files, text files contain only textual information, which can
be represented by alphabets, numbers, and other special symbols. These types of
files are saved with extensions such as.txt,.py,.c,.csv,.html, and so on. Each byte in
a text file corresponds to one character in the text.

Discuss this Question

75. The writelines() method is used to write multiple strings to a file?

A. True
B. False

Answer: A) True

Explanation:

In order to write multiple strings to a file, the writelines() method is used. The
writelines() method requires an iterable object, such as a list, tuple, or other
collection of strings, to be passed to it.
NUMPY

1. What does NumPy stand for?

a) Numerical Python
b) Natural Python
c) Numeric Program
d) Nonlinear Python

Answer: a) Numerical Python

Explanation: NumPy stands for Numerical Python, which is a library in


Python used for performing various mathematical operations and data
manipulations efficiently.

2. What is the default data type of NumPy arrays?

a) int32
b) float64
c) object
d) None of the above

Answer: b) float64

Explanation: The default data type of NumPy arrays is float6d) However, it


can be changed using the dtype parameter while creating the array.

3. What is the output of the following code?


import numpy as np
a = np.arange(10)
print(a[2:5])

a) [2, 3, 4]
b) [0, 1, 2]
c) [5, 6, 7]
d) [2, 4, 6]

Answer: a) [2, 3, 4]

Explanation: The code creates a NumPy array with elements from 0 to 9


using the arange() function. The slicing operation a[2:5] returns the
elements from index 2 to index 4, which is [2, 3, 4].

4. Which of the following is used to create an identity matrix in


NumPy?

a) zeros()
b) ones()
c) arange()
d) eye()

Answer: d) eye()

Explanation: The eye() function is used to create an identity matrix in


NumPy.

5. What is the output of the following code?


import numpy as np
a = np.array([[1, 2], [3, 4]])
print(a)ndim)

a) 0
b) 1
c) 2
d) 3

Answer: c) 2

Explanation: The code creates a NumPy array with two dimensions and
prints the number of dimensions using the ndim attribute, which is b)

6. Which of the following is used to calculate the mean of a NumPy


array?

a) mean()
b) average()
c) median()
d) All of the above

Answer: d) All of the above

Explanation: The mean(), average(), and median() functions can be used


to calculate the mean of a NumPy array.

7. Which of the following is used to reshape a NumPy array?


a) reshape()
b) resize()
c) Both A and B
d) None of the above

Answer: c) Both A and B

Explanation: The reshape() and resize() functions can be used to reshape a


NumPy array.

8. What is the output of the following code?

import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.stack((a, b))
print(c)

a) [[1, 2, 3], [4, 5, 6]]


b) [[1, 4], [2, 5], [3, 6]]
c) [1, 2, 3, 4, 5, 6]
d) Error

Answer: b) [[1, 4], [2, 5], [3, 6]]

Explanation: The code stacks two NumPy arrays vertically using the stack()
function and prints the result, which is a two-dimensional array with the
elements from both arrays stacked vertically.
9. Which of the following is used to find the maximum element in a
NumPy array?

a) max()
b) maximum()
c) amax()
d) All of the above

Answer: d) All of the above

Explanation: The max(), maximum(), and amax() functions can be used to


find the maximum element in a NumPy array.

10. What is the output of the following code?

import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c=a+b
print(c)

a) [1, 2, 3, 4, 5, 6]
b) [[1, 4], [2, 5], [3, 6]]
c) [5, 7, 9]
d) Error

Answer: c) [5, 7, 9]
Explanation: The code adds two NumPy arrays using the ‘+’ operator and
prints the result, which is a new NumPy array with the elements from both
arrays added together.

11. Which of the following is used to find the indices of the


maximum and minimum elements in a NumPy array?

a) argmax() and argmin()


b) max() and min()
c) amax() and amin()
d) None of the above

Answer: a) argmax() and argmin()

Explanation: The argmax() and argmin() functions can be used to find the
indices of the maximum and minimum elements in a NumPy array.

12. What is the output of the following code?

import numpy as np
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6], [7, 8]])
c = np.dot(a, b)
print(c)

a) [[19, 22], [43, 50]]


b) [[5, 6], [7, 8], [1, 2], [3, 4]]
c) [[1, 5], [2, 6], [3, 7], [4, 8]]
d) Error
Answer: a) [[19, 22], [43, 50]]

Explanation: The code performs matrix multiplication between two NumPy


arrays using the dot() function and prints the result, which is a new NumPy
array with the result of the multiplication.

13. Which of the following is used to find the standard deviation of a


NumPy array?

a) std()
b) var()
c) Both A and B
d) None of the above

Answer: a) std()

Explanation: The std() function is used to find the standard deviation of a


NumPy array.

14. What is the output of the following code?

import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.vstack((a, b))
print(c)

a) [[1, 2, 3], [4, 5, 6]]


b) [[1, 4], [2, 5], [3, 6]]
c) [1, 2, 3, 4, 5, 6]
d) Error

Answer: b) [[1, 4], [2, 5], [3, 6]]

Explanation: The code stacks two NumPy arrays vertically using the
vstack() function and prints the result, which is a two-dimensional array with
the elements from both arrays stacked vertically.

15. Which of the following is used to find the sum of the elements in
a NumPy array?

a) sum()
b) cumsum()
c) All of the above
d) None of the above

Answer: a) sum()

Explanation: The sum() function is used to find the sum of the elements in
a NumPy array.

16. Which of the following is used to find the median of a NumPy


array?

a) median()
b) mean()
c) mode()
d) None of the above
Answer: a) median()

Explanation: The median() function is used to find the median of a NumPy


array.

17. What is the output of the following code?

import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.concatenate((a, b))
print(c)

a) [[1, 2, 3], [4, 5, 6]]


b) [[1, 4], [2, 5], [3, 6]]
c) [1, 2, 3, 4, 5, 6]
d) Error

Answer: c) [1, 2, 3, 4, 5, 6]

Explanation: The code concatenates two NumPy arrays using the


concatenate() function and prints the result, which is a new NumPy array
with the elements from both arrays concatenated)

18. Which of the following is used to create an identity matrix in


NumPy?

a) identity()
b) eye()
c) ones()
d) None of the above

Answer: b) eye()

Explanation: The eye() function is used to create an identity matrix in


NumPy.

19. What is the output of the following code?

import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6]
c = np.outer(a, b)
print(c)

a) [[1, 2, 3], [4, 5, 6]]


b) [[1, 4], [2, 5], [3, 6]]
c) [1, 2, 3, 4, 5, 6]
d) Error

Answer: b) [[ 4 5 6]
[ 8 10 12]
[12 15 18]]

Explanation: The code uses the outer() function to compute the outer
product of two NumPy arrays and prints the result, which is a new two-
dimensional NumPy array. The outer product of two vectors a and b is a
matrix where each element is the product of one element from a and one
element from b)
20. Which of the following is used to compute the dot product of two
NumPy arrays?

a) dot()
b) inner()
c) All of the above
d) None of the above

Answer: a) dot()

Explanation: The dot() function is used to compute the dot product of two
NumPy arrays.

21. What is the output of the following code?

import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.dot(a, b)
print(c)

a) [[1, 2, 3], [4, 5, 6]]


b) [[1, 4], [2, 5], [3, 6]]
c) [1, 2, 3, 4, 5, 6]
d) 32

Answer: d) 32

Explanation: The code computes the dot product of two NumPy arrays
using the dot() function and prints the result, which is a scalar value. The
dot product of two vectors a and b is the sum of the products of the
corresponding elements of a and b)

22. Which of the following is used to find the inverse of a matrix in


NumPy?

a) inv()
b) inverse()
c) All of the above
d) None of the above

Answer: a) inv()

Explanation: The inv() function is used to find the inverse of a matrix in


NumPy.

23. What is the purpose of NumPy in Python?

a) To provide a powerful N-dimensional array object


b) To provide functions for performing mathematical operations on arrays
c) To provide tools for integrating C/C++ and Fortran code with Python
d) All of the above

Answer: d) All of the above

Explanation: NumPy is a popular Python library that is widely used for


numerical computing. It provides a powerful N-dimensional array object,
which can be used to represent vectors, matrices, and other numerical data)
NumPy also provides a variety of functions for performing mathematical
operations on arrays, including mathematical functions, linear algebra
functions, and random number generation functions. In addition, NumPy
provides tools for integrating C/C++ and Fortran code with Python, making
it a useful library for scientific computing and data analysis.

24. What does NumPy stand for?

a) Numerical Python
b) Numerical Processing
c) Numeric Parsing
d) None of the above

Answer: a) Numerical Python

Explanation: NumPy stands for Numerical Python. It is an open-source


Python library that is used for scientific computing and data analysis. NumPy
provides a powerful N-dimensional array object, which can be used to
represent vectors, matrices, and other numerical data) It also provides a
variety of functions for performing mathematical operations on arrays,
including mathematical functions, linear algebra functions, and random
number generation functions. NumPy is widely used in the scientific
computing and data analysis communities due to its speed, efficiency, and
ease of use.

25. How is the basic ndarray created in NumPy?

a) By passing a Python list or tuple to the np.array() function


b) By using the np.ndarray() constructor function
c) By converting a Python list or tuple to an ndarray using the np.asarray()
function
d) By using the np.zeros() or np.ones() functions to create an array filled
with zeros or ones, respectively

Answer: a) By passing a Python list or tuple to the np.array() function

Explanation: The basic ndarray in NumPy is created by passing a Python


list or tuple to the np.array() function. For example, to create a one-
dimensional array containing the values 1, 2, and 3, we can use the
following code:

python
import numpy as np
a = np.array([1, 2, 3])

This will create an array a with three elements, which can be accessed using
indexing: a[0] returns 1, a[1] returns 2, and a[2] returns c) Alternatively,
we can create a two-dimensional array by passing a nested list to the
np.array() function. For example:

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

This will create a two-dimensional array with two rows and three columns.
The first row contains the values 1, 2, and 3, and the second row contains
the values 4, 5, and 6. We can access elements of the array using indexing:
b[0, 1] returns 2 (the element in the first row and second column), and b[1,
2] returns 6 (the element in the second row and third column).

The NumPy MCQs provide a valuable opportunity to test your knowledge


and comprehension of this widely-used Python library for numerical
computing. By taking the NumPy MCQ Quiz, you can improve your skills and
be better equipped for real-world applications of NumPy.

1. NumPY stands for?


A. Numbering Python
B. Number In Python
C. Numerical Python
D. None Of the above
View Answer
Ans : C
Explanation: NumPy, which stands for Numerical Python, is a library consisting of
multidimensional array objects

2. Numpy developed by?


A. Guido van Rossum
B. Travis Oliphant
C. Wes McKinney
D. Jim Hugunin
View Answer
Ans : B
Explanation: Numpy developed by Travis Oliphant.

3. NumPy is often used along with packages like?


A. Node.js
B. Matplotlib
C. SciPy
D. Both B and C
View Answer
Ans : D
Explanation: NumPy is often used along with packages like SciPy (Scientific Python) and
Matplotlib (plotting library)

4. Which of the following Numpy operation are correct?


A. Mathematical and logical operations on arrays.
B. Fourier transforms and routines for shape manipulation.
C. Operations related to linear algebra.
D. All of the above
View Answer
Ans : D
Explanation: Using Numpy, a developer can perform all operations.

5. The most important object defined in NumPy is an N-dimensional


array type called?
A. ndarray
B. narray
C. nd_array
D. darray
View Answer
Ans : A
Explanation: The most important object defined in NumPy is an N-dimensional array type
called ndarray.

6. The basic ndarray is created using?


A. numpy.array(object, dtype = None, copy = True, subok = False, ndmin =
0)
B. numpy.array(object, dtype = None, copy = True, order = None, subok =
False, ndmin = 0)
C. numpy_array(object, dtype = None, copy = True, order = None, subok =
False, ndmin = 0)
D. numpy.array(object, dtype = None, copy = True, order = None, ndmin =
0)
View Answer
Ans : B

Explanation: It creates an ndarray from any object exposing array interface, or from any
method that returns an array : numpy.array(object, dtype = None, copy = True, order =
None, subok = False, ndmin = 0).

7. What will be output for the following code?

import numpy as np

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

A. [[1, 2, 3]]
B. [1]
C. [1, 2, 3]
D. Error
View Answer
Ans : C
Explanation: The output is as follows : [1, 2, 3]

8. What will be output for the following code?

import numpy as np

a = np.array([1, 2, 3,4,5], ndmin = 2)

print a

A. [[1, 2, 3, 4, 5]]
B. [1, 2, 3, 4, 5]
C. Error
D. Null
View Answer
Ans : A
Explanation: The output is as follows : [[1, 2, 3, 4, 5]]

9. What will be output for the following code?

import numpy as np

a = np.array([1, 2, 3], dtype = complex)

print a
A. [[ 1.+0.j, 2.+0.j, 3.+0.j]]
B. [ 1.+0.j]
C. Error
D. [ 1.+0.j, 2.+0.j, 3.+0.j]
View Answer
Ans : D
Explanation: The output is as follows : [ 1.+0.j, 2.+0.j, 3.+0.j]

10. What is the syntax for dtype object?


A. numpy.dtype(object, align, copy, subok)
B. numpy.dtype(object, align, copy)
C. numpy.dtype(object, align, copy, ndmin)
D. numpy_dtype(object, align, copy)
View Answer
Ans : B
Explanation: A dtype object is constructed using the following syntax :
numpy.dtype(object, align, copy)

11. Which of the following statement is false?


A. ndarray is also known as the axis array.
B. ndarray.dataitemSize is the buffer containing the actual elements of the
array.
C. NumPy main object is the homogeneous multidimensional array
D. In Numpy, dimensions are called axes
View Answer
Ans : A

Explanation: ndarray is also known as the "alias array".

12. Which of the following function stacks 1D arrays as columns into a


2D array?
A. row_stack
B. column_stack
C. com_stack
D. All of the above
View Answer
Ans : B

Explanation: column_stack is equivalent to vstack only for 1D arrays.


13. If a dimension is given as ____ in a reshaping operation, the other
dimensions are automatically calculated.
A. Zero
B. One
C. Negative one
D. Infinite
View Answer
Ans : C
Explanation: If a dimension is given as -1 in a reshaping operation, the other dimensions
are automatically calculated.

14. Which of the following statement is true?


A. Some ufuncs can take output arguments.
B. Broadcasting is used throughout NumPy to decide how to handle
disparately shaped arrays
C. Many of the built-in functions are implemented in compiled C code
D. The array object returned by __array_prepare__ is passed to the ufunc
for computation.
View Answer
Ans : D
Explanation: The array object returned by __array_prepare__ is passed to the ufunc for
computation is true

15. Which of the following sets the size of the buffer used in ufuncs?
A. bufsize(size)
B. setsize(size)
C. setbufsize(size)
D. size(size)
View Answer
Ans : C
Explanation: Adjusting the size of the buffer may therefore alter the speed at which ufunc
calculations of various sorts are completed.

16. Which of the following set the floating-point error callback function
or log object?
A. settercall
B. setterstack
C. setter
D. callstack
View Answer
Ans : A
Explanation: setter sets how floating-point errors are handled.

17. What will be output for the following code?

import numpy as np

dt = dt = np.dtype('i4')

print dt

A. int32
B. int64
C. int128
D. int16
View Answer
Ans : A
Explanation: The output is as follows : int32

18. What will be output for the following code?

import numpy as np

dt = np.dtype([('age',np.int8)])

a = np.array([(10,),(20,),(30,)], dtype = dt)

print a['age']
A. [[10 20 30]]
B. [10 20 30]
C. [10]
D. Error
View Answer
Ans : B
Explanation: The output is as follows : [10 20 30]

19. Each built-in data type has a character code that uniquely identifies
it.What is meaning of code "M"?
A. timedelta
B. datetime
C. objects
D. Unicode
View Answer
Ans : B
Explanation: "M" : datetime

20. What is the range of uint32 data type?


A. (-2147483648 to 2147483647)
B. (-32768 to 32767)
C. (0 to 65535)
D. (0 to 4294967295)
View Answer
Ans : D
Explanation: uint32 : Unsigned integer (0 to 4294967295)

1. What is the purpose of NumPy in Python?

A. To do numerical calculations
B. To do scientific computing
C. Both A and B
D. None of the mentioned above

Answer: C) Both A and B

Explanation:
NumPy is an abbreviation for 'Numerical Python.' NumPy is a Python library that
allows users to perform mathematical and logical operations on arrays. As a
result, NumPy is considered a Python package. There are multidimensional array
objects and a collection of routines for processing the arrays in this library, which
may be found here. NumPy consists of multidimensional array objects as well as a
collection of procedures for manipulating and processing those arrays.

Discuss this Question

2. NumPy package is capable to do fast operations on arrays.

A. True
B. False

Answer: A) True

Explanation:

NumPy package is capable to do fast operations on arrays including


mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier
transforms, basic linear algebra, basic statistical operations, random simulation
and much more.

Discuss this Question

3. Amongst which Python library is similar to Pandas?

A. NPy
B. RPy
C. NumPy
D. None of the mentioned above

Answer: C) NumPy

Explanation:
Like NumPy, Pandas is one of the most extensively used python libraries in data
science, and it is similar to NumPy. Data structures and analytical tools that are
high-performance and simple to use are provided by the system. The Pandas
library, in contrast to the NumPy library, which provides objects for multi-
dimensional arrays, provides an in-memory two-dimensional table object called
DataFrame.

Discuss this Question

4. Amongst which of the following is true with reference to Pip in Python?

A. Pip is a standard package management system


B. It is used to install and manage the software packages written in Python
C. Pip can be used to search a Python package
D. All of the mentioned above

Answer: D) All of the mentioned above

Explanation:

Pip is a standard package management system that is used to install and manage
software packages that are written in the Python programming language.

Discuss this Question

5. NumPy arrays can be ___.

A. Indexed
B. Sliced
C. Iterated
D. All of the mentioned above

Answer: D) All of the mentioned above

Explanation:
The index value of an array starts at zero, and each element is referred by the
index value of the previous member.

Slicing - Slicing is used when we need to extract a portion of an array from


another. This is accomplished by the use of slicing. We can indicate which part of
the array should be sliced by using the [start: end] syntax in conjunction with the
array name to give the start and end index values.

Iterating - The first axis of a multidimensional array is used to iterate through the
arrays, for example.

for x in b:
print(x)

Discuss this Question

6. Observe the following code and identify what will be the outcome?

import numpy as np

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

print(a)

A. [1 2 3 4 5]
B. [1 2 3 4 5 6]
C. [0 1 2 3 4 5 6]
D. None of the mentioned above

Answer: B) [1 2 3 4 5 6]

Explanation:

In the above code, an array of six elements declared and assign it to the variable
a. In the next line of code, a is printing. So, all the elements which are in array a
will be print on screen.

Discuss this Question


7. Observe the following code and identify what will be the outcome?

import numpy as np

x = np.array([[0, 1],
[2, 3]])
np.transpose(x)

A. array([[0, 2],
B. [1, 3]])
C. array([[0, 1],
D. [2, 3]])
E. array([[2, 3],
F. [0, 1]])
G. None of the mentioned above

Answer: A)

array([[0, 2],
[1, 3]])

Explanation:

In the above code, an array has been declared and stored in a variable x. And
then, matrix transposed and print.

Discuss this Question

8. Observe the following code and identify what will be the outcome?

import numpy as np

a = np.array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
b = a
b is a

A. True
B. False

Answer: A) True

Explanation:

In the above code, the matrix has assigned to the variable a and then copy it to
the variable b. Hence, when we will run the code it will print true i.e Boolean
value.

Discuss this Question

9. The ix_ function can be used to combine different vectors.

A. True
B. False

Answer: A) True

Explanation:

To acquire the result for each n-uplet, the ix_ function can be used to mix
different vectors together in one operation.

Discuss this Question

10. Observe the following code and identify what will be the outcome?

import numpy as np

a = np.array([10, 20, 30, 40])


b = np.array([18, 15, 14])
c = np.array([25, 24, 26, 28, 23])

x, y, z = np.ix_(a, b, c)

print(x)

A. [[[10]]
B.
C. [[20]]
D.
E. [[30]]
F.
G. [[40]]]
H. [[[1]]
I.
J. [[2]]
K.
L. [[3]]
M.
N. [[4]]
O.
P. [[5]]]
Q. [[[18]]
R.
S. [[15]]
T.
U. [[[14]]]
V. None of the mentioned above

Answer: A)

[[[10]]

[[20]]

[[30]]

[[40]]]

Explanation:

To acquire the result for each n-uplet, the ix_ function can be used to mix
different vectors together in one operation. In this case, if you wish to compute
all of the a+b*c for all of the triplets derived from each of the vectors a, b, and c.

Discuss this Question

11. What will be the output of the following Python code?


from numpy import random

x = random.randint(100)

print(x)

A. 56
B. 26
C. 40
D. All of the mentioned above

Answer: D) All of the mentioned above

Explanation:

In the above code, random.randint(100) function has been used which is used to
create any integer number till 100.

Discuss this Question

12. Binomial Distribution is a Discrete Distribution.

A. True
B. False

Answer: A) True

Explanation:

A Discrete Distribution is the same as a Binomial Distribution. If you toss a coin,


the outcome will be either heads or tails. This term explains the outcome of
binary circumstances. It is comprised of three parameters:

• n - is the number of tries.


• p - denotes the likelihood that each trial will occur (e.g. for toss of a coin
0.5 each).
• size - The size of the array that was returned.
Discuss this Question

13. Using ndim we can find -

A. We can find the dimension of the array


B. Size of array
C. Operational activities on Matrix
D. None of the mentioned above

Answer: A) We can find the dimension of the array

Explanation:

We can determine the dimension of an array, regardless of whether it is a two-


dimensional array or a single-dimensional array.

Discuss this Question

14. Observe the code and identify the outcome:

from numpy import random

x = random.binomial(n=100, p=0.5, size=10)

print(x)

A. [41 53 50 52 60 47 50 50 50 46]
B. [50 52 60 47 50 50 50 46]
C. [41 53 50 52 60 47 50]
D. None of the mentioned above

Answer: A) [41 53 50 52 60 47 50 50 50 46]

Explanation:

In the above code, binomial distribution has been used so the outcome of the
code will be [41 53 50 52 60 47 50 50 50 46].
Discuss this Question

15. What will be the output of following Python code?

import numpy as np

a = np.array([(10,20,30)])

print(a.itemsize)

A. 10
B. 9
C. 8
D. All of the mentioned above

Answer: C) 8

Explanation:

Using itemsize, we can determine the byte size of each element. In the above
code, a single-dimensional array has built, and we can determine the size of each
element with the aid of the itemsize function.

1. Pandas is an open-source _______ Library?


A. Ruby
B. Javascript
C. Java
D. Python
View Answer
Ans : D

Explanation: Pandas is an open-source Python Library providing high-performance data


manipulation and analysis tool using its powerful data structures.

2. Python pandas was developed by?


A. Guido van Rossum
B. Travis Oliphant
C. Wes McKinney
D. Brendan Eich
View Answer
Ans : C
Explanation: Pandas is a high-level data manipulation tool developed by Wes McKinney.

3. Pandas key data structure is called?


A. Keyframe
B. DataFrame
C. Statistics
D. Econometrics
View Answer
Ans : B

Explanation: Pandas is built on the Numpy package and its key data structure is called
the DataFrame.

4. What will be output for the following code?

import pandas as pd

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

print s['a']

A. 1
B. 2
C. 3
D. 4
View Answer
Ans : A
Explanation: Retrieve a single element using index label value.

5. In pandas, Index values must be?


A. unique
B. hashable
C. Both A and B
D. None of the above
View Answer
Ans : C
Explanation: Index values must be unique and hashable, same length as data. Default
np.arrange(n) if no index is passed.

6. 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)
View Answer
Ans : C

Explanation: A pandas Series can be created using the following constructor :


pandas.Series( data, index, dtype, copy)

7. Which of the following is correct Features of DataFrame?


A. Potentially columns are of different types
B. Can Perform Arithmetic operations on rows and columns
C. Labeled axes (rows and columns)
D. All of the above
View Answer
Ans : D
Explanation: All the above are feature of dataframe.

8. What will be syntax for pandas dataframe?


A. pandas.DataFrame( data, index, dtype, copy)
B. pandas.DataFrame( data, index, rows, dtype, copy)
C. pandas_DataFrame( data, index, columns, dtype, copy)
D. pandas.DataFrame( data, index, columns, dtype, copy)
View Answer
Ans : D
Explanation: A pandas DataFrame can be created using the following constructor :
pandas.DataFrame( data, index, columns, dtype, copy)
9. A panel is a ___ container of data
A. 1D
B. 2D
C. 3D
D. Infinite
View Answer
Ans : C
Explanation: A panel is a 3D container of data. The term Panel data is derived from
econometrics and is partially responsible for the name pandas : pan(el)-da(ta)-s.

10. Axis 1, in panel represent?


A. minor_axis
B. major_axis
C. items
D. None of the above
View Answer
Ans : B
Explanation: major_axis : axis 1, it is the index (rows) of each of the DataFrames.

11. Which of the following is true?


A. If data is an ndarray, index must be the same length as data.
B. Series is a one-dimensional labeled array capable of holding any data
type.
C. Both A and B
D. None of the above
View Answer
Ans : C

Explanation: Both option A and B are true.

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


A. a python dict
B. an ndarray
C. a scalar value
D. All of the above
View Answer
Ans : D
Explanation: The passed index is a list of axis labels.
13. 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 above
View Answer
Ans : A
Explanation: DataFrame.from_dict operates like the DataFrame constructor except for
the orient parameter which is 'columns' by default.

14. The ________ project builds on top of pandas and matplotlib to provide
easy plotting of data.
A. yhat
B. Seaborn
C. Vincent
D. Pychart
View Answer
Ans : B
Explanation: Seaborn has great support for pandas data objects.

15. Which of the following makes use of pandas and returns data in a
series or dataFrame?
A. pandaSDMX
B. freedapi
C. OutPy
D. Inpy
View Answer
Ans : B
Explanation: freedapi module requires a FRED API key that you can obtain for free on
the FRED website.

16. Why ndim is used?


A. Returns the number of elements in the underlying data.
B. Returns the Series as ndarray.
C. Returns the number of dimensions of the underlying data, by definition 1.
D. Returns a list of the axis labels
View Answer
Ans : C
Explanation: ndim : Returns the number of dimensions of the underlying data, by
definition 1

17. What will be output for the following code?

import pandas as pd

import numpy as np

s = pd.Series(np.random.randn(4))

print s.ndim

A. 0
B. 1
C. 2
D. 3
View Answer
Ans : B
Explanation: Returns the number of dimensions of the object. By definition, a Series is a
1D data structure, so it returns 1.

18. What will be output for the following code?

import pandas as pd

import numpy as np

s = pd.Series(np.random.randn(2))
print s.size

A. 0
B. 1
C. 2
D. 3
View Answer
Ans : C
Explanation: size : Returns the size(length) of the series.

19. Which of the following indexing capabilities is used as a concise


means of selecting data from a pandas object?
A. In
B. ix
C. ipy
D. iy
View Answer
Ans : B
Explanation: ix and reindex are 100% equivalent.

20. Which of the following is false?


A. The integer format tracks only the locations and sizes of blocks of data.
B. Pandas follow the NumPy convention of raising an error when you try to
convert something to a bool.
C. Two kinds of SparseIndex are implemented
D. The integer format keeps an arrays of all of the locations where the data
are not equal to the fill value
View Answer
Ans : A
Explanation: The block format tracks only the locations and sizes of blocks of data.

You might also like