MCQ Python
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
a. 16
b. 32
c. 64
d. None of these above
a. Zim Den
b. Guido van Rossum
c. Niene Stom
d. Wick van Rossum
a. 1995
b. 1972
c. 1981
d. 1989
PlayNext
Unmute
Duration 18:10
Loaded: 0.37%
Â
Fullscreen
Backward Skip 10sPlay VideoForward Skip 10s
a. English
b. PHP
c. C
d. All of the above
5) Which one of the following is the correct extension of the Python file?
a. .py
b. .python
c. .p
d. None of these
a. 2008
b. 2000
c. 2010
d. 2005
a. Key
b. Brackets
c. Indentation
d. None of these
a. /
b. //
c. #
d. !
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
a. Object
b. Function
c. Attribute
d. Argument
a. _x = 2
b. __x = 3
c. __xyz__ = 5
d. None of these
a. val
b. raise
c. try
d. with
15) Which of the following statements is correct for variable names 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
a. _val
b. val
c. try
d. _try_
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
20) Which one of the following has the same precedence level?
21) Which one of the following has the highest precedence in the expression?
a. Division
b. Subtraction
c. Power
d. Parentheses
a. val()
b. print()
c. print()
d. None of these
1. round(4.576)
a. 4
b. 5
c. 576
d. 5
1. pow(x,y,z)
a. (x**y) / z
b. (x / y) * z
c. (x**y) % z
d. (x / y) / z
1. all([2,4,0,6])
a. False
b. True
c. 0
d. Invalid code
1. x = 1
2. while True:
3. if x % 5 = = 0:
4. break
5. print(x)
6. x+=1
27) Which one of the following syntaxes is the correct syntax to read from a simple text file
stored in ''d:\java.txt''?
1. x = ['XX', 'YY']
2. for i in a:
3. i.lower()
4. print(a)
a. ['XX', 'YY']
b. ['xx', 'yy']
c. [XX, yy]
d. None of these
a. Error
b. -6
c. 6
d. 6.0
a. False
b. Ture
c. Invalid code
d. None of these
1. >>>"a"+"bc"
a. a+bc
b. abc
c. a bc
d. a
Show Answer Workspace
1. >>>"javatpoint"[5:]
a. javatpoint
b. java
c. point
d. None of these
a. character
b. ascii_lowercase_string.digits
c. lowercase_string.upercase
d. ascii_lowercase+string.ascii_upercase
a. t
b. j
c. point
d. java
a. java
point
b. java point
c. \njavat\npoint
d. Print the letter r and then javat and then point
a. 33
b. 63
c. 0xA + 0xB + 0xC
d. None of these
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)
a. 32
b. 32 32
c. 32 None
d. Error is generated
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)
a. 18
b. -18
c. 17
d. -17
1. x = ['xy', 'yz']
2. for i in a:
3. i.upper()
4. print(a)
a. ['xy', 'yz']
b. ['XY', 'YZ']
c. [None, None]
d. None of these
1. i = 1:
2. while True:
3. if i%3 == 0:
4. break
5. print(i)
a. 123
b. 3 2 1
c. 1 2
d. Invalid syntax
1. a = 1
2. while True:
3. if a % 7 = = 0:
4. break
5. print(a)
6. a += 1
a. 12345
b. 1 2 3 4 5 6
c. 1 2 3 4 5 6 7
d. Invalid syntax
1. i = 0
2. while i < 5:
3. print(i)
4. i += 1
5. if i == 3:
6. break
7. else:
8. print(0)
a. 123
b. 0 1 2 3
c. 0 1 2
d. 3 2 1
1. i = 0
2. while i < 3:
3. print(i)
4. i += 1
5. else:
6. print(0)
a. 01
b. 0 1 2
c. 0 1 2 0
d. 0 1 2 3
1. z = "xyz"
2. j = "j"
3. while j in z:
4. print(j, end=" ")
a. xyz
b. No output
c. x y z
d. j j j j j j j..
1. x = 'pqrs'
2. for i in range(len(x)):
3. x[i].upper()
4. print (x)
a. PQRS
b. pqrs
c. qrs
d. None of these
a. abc
b. 0 1 2
c. 0 a 1 b 2 c
d. None of these above
1. d = {0, 1, 2}
2. for x in d:
3. print(x)
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
50) What error will occur when you execute the following code?
1. MANGO = APPLE
a. NameError
b. SyntaxError
c. TypeError
d. ValueError
1. def example(a):
2. aa = a + '1'
3. aa = a*1
4. return a
5. >>>example("javatpoint")
a. hello2hello2
b. hello2
c. Cannot perform mathematical operation on strings
d. indentationError
a. Dictionary
b. Tuple
c. List
d. Stack
a. False
b. Ture
c. ValueError occurs
d. TypeError occurs
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")
a. invalid code
b. JavaTpoint has not exist
c. JavaTpoint has exist
d. none of these above
Show Answer Workspace
1. z = {"x":0, "y":1}
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. print(print(print("javatpoint")))
PlayNext
Unmute
Current Time 12:35
Duration 18:10
Loaded: 74.85%
Â
Fullscreen
Backward Skip 10sPlay VideoForward Skip 10s
1. int1 = 10
2. int2 = 6
3. if int != int2:
4. int2 = ++int2
5. print(int1 - int2)
a. 2
b. 4
c. 6
d. None
a. 2
b. 4
c. 0
d. No Output
1. print(6 + 5 - 4 * 3 / 2 % 1)
a. 7
b. 7.0
c. 15
d. 0
1. int1 = 0b0010
2. print(int1)
a. 0b0010
b. 2
c. NameError: name '0b0010' is not defined
d. SyntaxError
1. word = "javatpoint"
2. print(*word)
a. javatpoint
b. j a v a t p o i n t
c. *word
d. SyntaxError: invalid syntax
1. i = 2, 10
2. j = 3, 5
3. add = i + j
4. print(add)
a. (5, 10)
b. 20
c. (2, 10, 3, 5)
d. SyntaxError: invalid syntax
1. print(int(6 == 6.0) * 3 + 4 % 5)
a. 22
b. 18
c. 20
d. 7
1. i = 2
2. j = 3, 5
3. add = i + j
4. print(add)
a. 5, 5
b. 5
c. (2 , 3 , 5)
d. TypeError
a. Four
b. Five
c. Three
d. None of the these
a. 32
b. 61
c. 33
d. 27
13) Which of the following arithmetic operators cannot be used with strings in python?
a. +
b. *
c. -
d. All of the mentioned
a. javapoint2
b. japoint
c. java2point
d. javapoin2
1. _ = '1 2 3 4 5 6'
2. print(_)
a. None
b. class
c. goto
d. and
1. a = '1 2'
2. print(a * 2)
3. print(a * 0)
4. print(a * -2)
a. 1212
b. 2 4
c. 0
d. -1 -2 -1 -2
a. 145
b. 122
c. a
d. z
1. a = "123789"
2. while x in a:
3. print(x, end=" ")
a. Python interpreter
b. Python compiler
c. Python volatile machine
d. Portable virtual machine
1. i = {4, 5, 6}
2. i.update({2, 3, 4})
3. print(i)
a. 234456
b. 2 3 4 5 6
c. 4 5 6 2 3 4
d. Error, duplicate element presents in list
a. 0 1 12 20 25
b. 1 12 20 25
c. FunctionError
d. AttributeError
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
25) Which of the following objects are present in the function header in python?
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
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
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]
1. str1="python language"
2. str1.find("p")
3. print(str1)
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)
a. 12
b. 4
c. 11
d. 16
a. String type
b. Array lists
c. List of tuples
d. str lists
32) Which of the following statements is not valid regarding the variable in python?
1. a = 2
2. while(a > -100):
3. a=a-1
4. print(a)
a. Infinite
b. 102
c. 2
d. 1
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)
a. 32 0
b. 0 32
c. 18 0
d. 0 18
a. if f >= 12:
b. if (f >= 122)
c. if (f => 1222)
d. if f >= 12222
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
1. try:
2. print(file_name)
3. except:
4. print("error comes in the line")
a. file_name
b. error
c. error comes in the line
d. file_name error comes in the line
1. i = 10
2. j = 8
3. assert i > j, 'j = i + j'
4. print(j)
a. 18
b. 8
c. No output
d. TypeError
a. 1
b. 2
c. 3
d. None of the these
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)
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)
a. 20 John 30
b. 20 30
c. John 30
d. 30 John 20
42) Which of the following code will create a set in python language?
3. thisset = {}
a. 1 only
b. 1 and 2 both
c. 1, 2, and 3 will create a set
d. None of the these
a. {0, 0, 'a1', 0, 9}
b. {0, 'a1', 0, 9}
c. {0, 9, 'a1'}
d. {0, 0, 9, 0, 'a1'}
1. mytuple1=(5, 1, 7, 6, 2)
2. mytuple1.pop(2)
3. print(mytuple1)
a. 51762
b. No output
c. AttributeError
d. None of the these
46) Which of the following functions returns a list containing all matches?
a. find
b. findall
c. search
d. None of the these
1. mytuple1 = (2, 4, 3)
2. mytuple3 = mytuple1 * 2
3. print(mytuple3)
a. (2, 4, 3, 2, 4, 3)
b. (2, 2, 4, 4, 3, 3)
c. (4, 8, 6)
d. Error
48) In the Python Programming Language, syntax error is detected by ______ at _________.
a. 10 11 11 12
b. 10 11 11 13
c. 10 8 6 4
d. SyntaxError
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
A. Special purpose
B. General purpose
C. Medium level programming language
D. All of the mentioned above
Explanation:
Explanation:
Python programming was created by Guido van Rossum. It is also called general-
purpose programming language.
A. Web Development
B. Game Development
C. Artificial Intelligence and Machine Learning
D. All of the mentioned above
Explanation:
A. int
B. float
C. complex
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.
A. Sequence Types
B. Binary Types
C. Boolean Types
D. None of the mentioned above
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.
ADVERTISEMENT
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.
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.
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.
Answer: A) True
Explanation:
A. TRUE
B. FALSE
Answer: A) TRUE
Explanation:
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
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.
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.
A. Exponentiation
B. Modulus
C. Floor division
D. None of the mentioned above
Answer: A) Exponentiation
Explanation:
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.
A. append()
B. extend()
C. insert()
D. All of the mentioned above
Explanation:
ADVERTISEMENT
16. The list.pop ([i]) removes the item at the given position in the list?
A. True
B. False
Answer: A) True
Explanation:
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.
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.
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>
}
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:
ADVERTISEMENT
A. Decision-making
B. Array
C. List
D. None of the mentioned above
Answer: A) Decision-making
Explanation:
A. True
B. False
Answer: A) True
Explanation:
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
A. if a<=100:
B. if (a >= 10)
C. if (a => 200)
D. None of the mentioned above
Answer: A) if a<=100:
Explanation:
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.
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.
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
Explanation:
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
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.
ADVERTISEMENT
x=13
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".
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
Explanation:
A. Block
B. Loop
C. Indentation
D. None of the mentioned above
Answer: C) Indentation
Explanation:
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:
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."
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
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.
Answer: A) True
Explanation:
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
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.
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,
40. If a condition is true the not operator is used to reverse the logical state?
A. True
B. False
Answer: A) True
Explanation:
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.
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 –
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.
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.
45. Amongst which of the following is / are true about the while loop?
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:
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.
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.
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.
50. Amongst which of the following is / are true with reference to loops in
Python?
Explanation:
Following point's shows the importance of loops in Python.
A. Write code
B. Specific task
C. Create executable file
D. None of the mentioned above
Explanation:
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
...
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 + ".")
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
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.
def show(id,name):
print("Your id is :",id,"and your name is :",name)
show(12,"deepak")
Explanation:
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
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:
A. Yes
B. No
Answer: A) Yes
Explanation:
def St_list(student):
for x in student:
print(x)
students = ["Anil", "Rex", "Jerry"]
St_list(students)
"""
Output:
Anil
Rex
Jerry
"""
A. True
B. False
Answer: A) True
Explanation:
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.
60. Scope and lifetime of a variable declared in a function exist till the
function exists?
A. True
B. False
Answer: A) True
Explanation:
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.
62. Amongst which of the following is / are the key functions used for file
handling in Python?
Explanation:
A. filename
B. mode
C. Both A and B
D. None of the mentioned above
Explanation:
In most cases, only the filename and mode parameters are required, with the rest
of the parameters implicitly set to their default values.
f = open ("file.txt")
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
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.
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.
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.
Explanation:
The seek() method is used to position a file object at a specific location within a
file's hierarchy.
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.
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.
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.
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
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.
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
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.
A. Alphabets
B. Numbers
C. Special symbols
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.
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
a) Numerical Python
b) Natural Python
c) Numeric Program
d) Nonlinear Python
a) int32
b) float64
c) object
d) None of the above
Answer: b) float64
a) [2, 3, 4]
b) [0, 1, 2]
c) [5, 6, 7]
d) [2, 4, 6]
Answer: a) [2, 3, 4]
a) zeros()
b) ones()
c) arange()
d) eye()
Answer: d) eye()
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)
a) mean()
b) average()
c) median()
d) All of the above
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.stack((a, b))
print(c)
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
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.
Explanation: The argmax() and argmin() functions can be used to find the
indices of the maximum and minimum elements in a NumPy array.
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) std()
b) var()
c) Both A and B
d) None of the above
Answer: a) std()
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.vstack((a, b))
print(c)
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.
a) median()
b) mean()
c) mode()
d) None of the above
Answer: a) median()
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.concatenate((a, b))
print(c)
Answer: c) [1, 2, 3, 4, 5, 6]
a) identity()
b) eye()
c) ones()
d) None of the above
Answer: b) eye()
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6]
c = np.outer(a, b)
print(c)
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.
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.dot(a, b)
print(c)
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)
a) inv()
b) inverse()
c) All of the above
d) None of the above
Answer: a) inv()
a) Numerical Python
b) Numerical Processing
c) Numeric Parsing
d) None of the above
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).
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).
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]
import numpy as np
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]]
import numpy as np
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]
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.
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
import numpy as np
dt = np.dtype([('age',np.int8)])
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
A. To do numerical calculations
B. To do scientific computing
C. Both A and B
D. None of the mentioned above
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.
A. True
B. False
Answer: A) True
Explanation:
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.
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.
A. Indexed
B. Sliced
C. Iterated
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.
Iterating - The first axis of a multidimensional array is used to iterate through the
arrays, for example.
for x in b:
print(x)
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.
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.
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.
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.
10. Observe the following code and identify what will be the outcome?
import numpy as np
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.
x = random.randint(100)
print(x)
A. 56
B. 26
C. 40
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.
A. True
B. False
Answer: A) True
Explanation:
Explanation:
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
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
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.
Explanation: Pandas is built on the Numpy package and its key data structure is called
the DataFrame.
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.
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.
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.
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.