Python Basics MCQs

This section focuses on the "Basics" of the Python. These Multiple Choice Questions (mcq) should be practiced to improve the Python skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. What will be the output of the following program on execution?

a=0
b=5
x=(a&b)|(a&a)|(a|b)
print("x")

A. 1
B. 5
C. 0
D. None of the above

View Answer


2. What will be the output of the following program on execution?

a=0
b=6
x=(a&b)|(a&a | a&b)
y=not(x)
print(y)

A. 6
B. True
C. 0
D. False

View Answer


3. What will be the output of the following program on execution?

if False:
print ("inside if block")
elif True:
print ("inside elif block")
else:
print ("inside else block")

A. inside if block
B. inside elif block
C. inside else block
D. Error

View Answer


4. What will be the values of var1 and var2 after the execution of program?

var=3
var1=0
var2=var1+1
while(var<7):
var2=var2+var1
if(var1%2==0):
var=var+1
var1=var1+1
else:
var2=var2*var1
var1=var1+3

A. 12,648
B. 13,648
C. 13,660
D. 9,72

View Answer


5. Which of the following statements are correct?
(i) Python is a high level programming language.
(ii) Python is an interpreted language.
(iii) Python is a compiled language.
(iv) Python program is compiled before it is interpreted.

A. i, ii
B. i, iv
C. ii, iii
D. ii, iv

View Answer


6.  Which of the given options has same output as given statement?

If var1=7
var2=5
var3=1
var4=10
var5=20
(var1*var2)>(var5+var4*var3) and ((var5+var3)/var1)>=(var2-2)/var3

A. (var5/var4)>var3 and (var3*var2)>=(var1*var3)
B. (var5-var4)*var2
C. (var4/var2)>var1 and (var1*3)/var3
D. (var1/var3)>var4 or var5*2==var4

View Answer


7. Which of the following is incorrect variable name in Python?

A. variable_1
B. variable1
C. 1variable
D. _variable

View Answer


8. What will be the output of following Python code snippet?

for i in range(0 , -2 , -1):
print(i)

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

View Answer


9. What will be the output of following Python code snippet?

str1="012"
num1=2
num2=0
for i in range(4):
num1+=2
for j in range(len(str1)):
num2=num2+num1
num3=num2%int(str1)
print(num3)

A. 7
B. Infinite Loop
C. 0
D. Error

View Answer


10. What will be the result of following Python code snippet after execution?

a=0
b=1
if (a and b):
print("hi")
elif(not(a)):
print("hello")
elif(b):
print("hi world")
else:
print("hello world")

A. hello world
B. hi
C. hi world
D. hello

View Answer


11. What will be the result of following Python code snippet after execution?

str1=""
i=0
var2=1
while(i<3):
var1=1
if str1:
var2=var1*var2+5
else:
var2=var1*var2+1
i=i+1
print(var2)

A. 16
B. 12
C. 11
D. 4

View Answer


12. Which of the following are in correct order with respect to conditional statements in Python?
(i) if
(ii) else
(iii) elif

A. i, iii, ii
B. ii, iii ,i
C. iii, ii, i
D. ii, i, iii

View Answer


13. Which of the following is not a relational opeartor in Python?

A. >=
B. <=
C. =
D. !=

View Answer


14. Which of the following two will give the same result?
(i) 42//2
(ii) 21%6
(iii) 12/4
(iv) 11*2

A. ii,iii
B. i, iii
C. ii, iv
D. iii, iv

View Answer


15. Suppose we have two sets A & B, then A < B is:

A. True if len(A) is less than len(B).
B. True if A is a proper subset of B.
C. True if the elements in A when compared are less than the elements in B.
D. True if A is a proper superset of B.

View Answer


16. Which of the following is incorrect?

A. List is a built-in data structure in Python
B. List can only have elements of same data type.
C. List is mutable.
D. Index of lists can be positive as well as negative.

View Answer


17. Which of the following will result in error?
(i) list1[3]=list1[2]
(ii) list1[3]=list1[4]
(iii) list1.insert(1,78)
(iv) list1.pop(50)

If list1=[10,20,60,50]

A. i, iii
B. i, iv
C. ii, iv
D. ii, iii

View Answer


18. Which of the following operations cannot be done on string str1, where str1="LETSFINDCOURSE."?

A. str1+="Learning made easy"
B. str1[1]="a"
C. print(str1[1])
D. str1[0:4]

View Answer


19. If str1="Programming Language"
What does str1.find("m") return?

A. Number of occurances of "m" in string str1.
B. Index positions of "m" in the string str1.
C. It returns the whole string str1 if it contains "m".
D. It returns the index position of first occurance of "m" in the string str1.

View Answer


20. Which of the following would give "Harry" as output?
Given str1="Mary,Harry,John,Sam"

A. str1[4:9]
B. str1[5:10]
C. str1[4:10]
D. str1[5:9]

View Answer





Also check :


Discussion



* You must be logged in to add comment.

Jayanth Gundeti
answer for 6th question is option D (i e 4 is Answer)