1) Who developed the Python language?
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
3) What do we use to define a block of code in Python language?
a. Key
b. Brackets
c. Indentation
d. None of these
4) Which character is used in Python to make a single line comment?
a. /
b. //
c. #
d. !
5) What is the method inside the class in python language?
a. Object
b. Function
c. Attribute
d. Argument
6) Which of the following statements is correct in this python code?
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
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
7) Which of the following declarations is incorrect?
a. _x = 2
b. __x = 3
c. __xyz__ = 5
d. None of these
8) 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
9) Which of the following words cannot be a variable in python language?
a. _val
b. val
c. try
d. _try_
10) Study the following function:
all([2,4,0,6])
What will be the output of this function?
a. False
b. True
c. 0
d Invalid code
11) Study the following program:
x = 1
while True:
if x % 5 = = 0:
break
print(x)
x + = 1
What will be the output of this code?
a. error
b. 2 1
c. 0 3 1
d. None of these
12) Study the following function:
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
13) Study the following statement:
"a"+"bc"
What will be the output of this statement?
a. a+bc
b. abc
c. a bc
d. a
14) Study the following statements:
>>> str1 = "javat"
>>> str2 = ":"
>>> str3 = "point"
>>> str1[-1:]
What will be the output of this statement?
a. t
b. j
c. point
d. java
15) Study the following statements:
>>> print(0xA + 0xB + 0xC)
What will be the output of this statement?
a. 33
b. 63
c. 0xA + 0xB + 0xC
d. None of these
16) Study the following program:
i = 1:
while True:
if i%3 == 0:
break
print(i)
Which of the following is the correct output of this program?
a. 1 2 3
b. 3 2 1
c. 1 2
d. Invalid syntax
17) Study the following program:
z = "xyz"
j = "j"
while j in z:
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..
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
20) Study the following program
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
21) Study the following program
word = "javatpoint"
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
22) Study the following program:
print(int(6 == 6.0) * 3 + 4 % 5)
What will be the output of this program?
a. 22
b. 18
c. 20
d. 7
23) Study the following program:
i = 2
j = 3, 5
add = i + j
print(add)
What will be the output of this program?
a. 5, 5
b. 5
c. (2 , 3 , 5)
d. TypeError
24) Study the following program:
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
25) Which of the following keywords is not reversed keyword in python?
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)
What will be the output of this program?
a. 1 2 1 2
b. 24
c. 0
d. -1 -2 -1 -2
27) Study the following program:
i=(12, 20, 1, 0, 25)
i.sort()
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
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
30) Study the following program:
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)
What will be the output of this program?
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)
What will be the output of this program?
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?
for i in [1, 2, 3, 4][::-1]:
print (i)
a) 4 3 2 1
b) error
c) 1 2 3 4
d) none of the mentioned
34) Which of the following statements is used to create an empty set in
Python?
a) ( )
b) [ ]
c) { }
d) set()
35) To add a new element to a list we use which Python command?
a) list1.addEnd(5)
b) list1.addLast(5)
c) list1.append(5)
d) list1.add(5)
36)Which one of the following is the use of function in python?
a) Functions don’t provide better modularity for your application
b) you can’t also create your own functions
c) Functions are reusable pieces of programs
d) All of the mentioned
37) Which of the following Python statements will result in the output: 6?
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]
38)Which of the following is a feature of Python DocString?
a) In Python all functions should have a docstring
b) Docstrings can be accessed by the __doc__ attribute on objects
c) It provides a convenient way of associating documentation with Python
modules, functions, classes, and methods
d) All of the mentioned
39) What will be the output of the following Python expression?
round(4.5676,2)?
a) 4.5
b) 4.6
c) 4.57
d) 4.56
40. What will be the output of the following Python function?
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('The sum of {0:b} and {1:x} is {2:o}'.format(2, 10, 12))
a) The sum of 2 and 10 is 12
b) The sum of 10 and a is 14
c) The sum of 10 and a is c
d) Error
42) Study the following program:
print(6 + 5 - 4 * 3 / 2 % 1)
What will be the output of this program?
a. 7
b. 7.0
c. 15
d. 11.0
43) What is the output of the following?
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?
a) Recursive function can be replaced by a non-recursive function
b) Recursive functions usually take more memory space than non-recursive
function
c) Recursive functions run faster than non-recursive function
d) Recursion makes programs easier to understand
45) What is tail recursion?
a) A recursive function that has two base cases
b) A function where the recursive functions leads to an infinite loop
c) A recursive function where the function doesn’t return anything and just
prints the values
d) A function where the recursive call is the last thing executed by the function
46) What will be the output of the following Python code?
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
47) What will be the output of the following Python code?
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
49) ______________ returns a dictionary of the module namespace.
________________ returns a dictionary of the current namespace.
a)
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