Pythonmcq
Pythonmcq
a. Zim Den
b. Guido van Rossum
c. Niene Stom
d. Wick van Rossum
2) Which one of the following is the correct extension of the Python file?
a. .py
b. .python
c. .p
d. None of these
a. Key
b. Brackets
c. Indentation
d. None of these
a. /
b. //
c. #
d. !
a. Object
b. Function
c. Attribute
d. Argument
class Name:
def __init__(javatpoint):
javajavatpoint = java
name1=Name("ABC")
name2=name1
a. It will throw the error as multiple references to the same object is not
possible
c. Both name1 and name2 will have reference to two different objects of
class Name
a. _x = 2
b. __x = 3
c. __xyz__ = 5
d. None of these
b. Unlimited length
a. _val
b. val
c. try
d. _try_
all([2,4,0,6])
a. False
b. True
c. 0
d Invalid code
x = 1
while True:
if x % 5 = = 0:
break
print(x)
x + = 1
a. error
b. 2 1
c. 0 3 1
d. None of these
any([5>8, 6>3, 3>1])
"a"+"bc"
a. a+bc
b. abc
c. a bc
d. a
>>> str1 = "javat"
>>> str2 = ":"
>>> str3 = "point"
>>> str1[-1:]
a. t
b. j
c. point
d. java
>>> print(0xA + 0xB + 0xC)
a. 33
b. 63
c. 0xA + 0xB + 0xC
d. None of these
i = 1:
while True:
if i%3 == 0:
break
print(i)
a. 1 2 3
b. 3 2 1
c. 1 2
d. Invalid syntax
z = "xyz"
j = "j"
while j in z:
print(j, end=" ")
a. xyz
b. No output
c. x y z
d. j j j j j j j..
18) 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
19) What error will occur when you execute the following code?
MANGO = APPLE
a. NameError
b. SyntaxError
c. TypeError
d. ValueError
print(print(print("javatpoint")))
word = "javatpoint"
print(*word)
a. javatpoint
b. j a v a t p o i n t
c. *word
d. SyntaxError: invalid syntax
print(int(6 == 6.0) * 3 + 4 % 5)
i = 2
j = 3, 5
add = i + j
print(add)
a. 5, 5
b. 5
c. (2 , 3 , 5)
d. TypeError
print('It\'s ok, don\'t worry')
a. None
b. class
c. goto
d. and
26) Study the following program:
a = '1 2'
print(a * 2)
print(a * 0)
print(a * -2)
a. 1 2 1 2
b. 24
c. 0
d. -1 -2 -1 -2
i=(12, 20, 1, 0, 25)
i.sort()
print(i)
a. 0 1 12 20 25
b. 1 12 20 25
c. FunctionError
d. AttributeError
28) 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
29) 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
arr = [3 , 2 , 5 , 6 , 0 , 7, 9]
add1 = 0
add2 = 0
for elem in arr:
if (elem % 1 == 0):
add1 = add1 + elem
continue
if (elem % 3 == 0):
add2 = add2 + elem
print(add1 , end=" ")
print(add2)
a. 32 0
b. 0 32
c. 18 0
d. 0 18
31) 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
32) Study the following program:
mytuple1=(5, 1, 7, 6, 2)
mytuple1.pop(2)
print(mytuple1)
a. 5 1 7 6 2
b. No output
c. AttributeError
d. None of the these
33) What will be the output of the following Python code snippet?
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
a) A[2][1]
b) A[1][2]
c) A[3][2]
d) A[2][3]
round(4.5676,2)?
a) 4.5
b) 4.6
c) 4.57
d) 4.56
sum(2,4,6)
sum([1,2,3])
a) Error, 6
b) 12, Error
c) 12, 6
d) Error, Error
41) What will be the output of the following Python code snippet?
print(6 + 5 - 4 * 3 / 2 % 1)
a. 7
b. 7.0
c. 15
d. 11.0
my_string = 'geeksforgeeks'
for i in range(len(my_string)):
print (my_string)
my_string = 'a'
a. gaaaaaaaaaaaa
b. geeksforgeeks a a a a a a a a a a a a
c. Error
d. None
44)Which of these is false about recursion?
def a(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return a(n-1)+a(n-2)
for i in range(0,4):
print(a(i),end=" ")
a) 0 1 2 3
b) An exception is thrown
c) 0 1 1 2 3
d) 0 1 1 2
l=[]
def convert(b):
if(b==0):
return l
dig=b%2
l.append(dig)
convert(b//2)
convert(6)
l.reverse()
for i in l:
print(i,end="")
a) 011
b) 110
c) 3
d) Infinite loo
48) Which of the following data structures is returned by the functions
globals() and locals()?
a) list
b) set
c) dictionary
d) tuple
locals()
globals()
b)
locals()
locals()
c)
globals()
locals()
d)
globals()
globals()
50) Methods of a class that provide access to private members of the class are
called as ______ and ______
a) getters/setters
b) __repr__/__str__
c) user-defined functions/in-built functions
d) __init__/__del__
1. b
2. a
3. c
4. c
5. b
6. b
7. d
8. b
9. c
10. b
11. a
12.b
13.b
14.a
15.a
16.d
17.b
18.c
19.a
20.a
21.b
22.d
23.d
24.a
25.c
26.a
27.d
28.c
29.c
30.a
31.b
32.c
33.a
34.d
35.c
36.c
37.b
38.d
39.c
40.a
41.b
42.d
43.b
44.c
45.d
46.d
47.b
48.c
49.c
50. a