Basic Python MCQs:
What is the correct extension of a Python file?
- a)
.pyth
- b)
.pt
- c)
.py
- d)
.pyt
- Answer: c)
.py
- a)
Which of the following is a valid variable name in Python?
- a)
2variable
- b)
variable-name
- c)
variable_name
- d)
variable.name
- Answer: c)
variable_name
- a)
What is the output of the following code?
pythonprint(3 + 4 * 2)
- a) 14
- b) 11
- c) 10
- d) 7
- Answer: b) 11
Which of the following is NOT a valid Python data type?
-
a)
int
- b)
float
- c)
double
- d)
str
- Answer: c)
double
-
a)
What will the following code output?
pythonprint(type(10))
- a)
<class 'str'>
- b)
<class 'int'>
- c)
<class 'float'>
- d)
<class 'bool'>
- Answer: b)
<class 'int'>
- a)
Which of the following functions is used to get user input in Python?
- a)
input()
- b)
get()
- c)
scan()
- d)
read()
- Answer: a)
input()
- a)
Which of the following is the correct way to write a comment in Python?
- a)
// This is a comment
- b)
# This is a comment
- c)
/* This is a comment */
- d)
<!-- This is a comment -->
- Answer: b)
# This is a comment
- a)
What will the following code return?
pythonprint(10 // 3)
- a) 3.33
- b) 3
- c) 3.0
- d) 4
- Answer: b) 3
Which of the following is used to define a block of code in Python?
- a) Curly brackets
{ }
- b) Parentheses
( )
- c) Indentation
- d) Quotation marks
- Answer: c) Indentation
- a) Curly brackets
What will the following code output?
pythonx = "Hello" y = "World" print(x + y)
- a)
HelloWorld
- b)
Hello World
- c)
Hello+World
- d)
Error
- Answer: a)
HelloWorld
- a)
More Basic Python MCQs:
Which of the following is the correct syntax to create a function in Python?
- a)
function myFunction():
- b)
def myFunction():
- c)
create myFunction():
- d)
func myFunction():
- Answer: b)
def myFunction():
- a)
What will the following code output?
pythonprint(type([1, 2, 3]))
- a)
<class 'list'>
- b)
< class 'tuple'>
- c)
<class 'set'>
- d)
<class 'dict'>
- Answer: a)
<class 'list'>
- a)
Which of the following operators is used for exponentiation in Python?
- a)
^
- b)
%
- c)
**
- d)
*
- Answer: c)
**
- a)
What is the output of the following code?
pythonprint(5 % 2)
- a) 2
- b) 1
- c) 0
- d) 5
- Answer: b) 1
Which of the following is NOT a keyword in Python?
- a)
def
- b)
for
- c)
print
- d)
while
- Answer: c)
print
- a)
How can you create a list in Python?
- a)
list = {1, 2, 3}
- b)
list = (1, 2, 3)
- c)
list = [1, 2, 3]
- d)
list = <1, 2, 3>
- Answer: c)
list = [1, 2, 3]
- a)
What will the following code output?
pythonx = [1, 2, 3, 4] print(len(x))
- a) 4
- b) 5
- c) 3
- d) 2
- Answer: a) 4
What does the
len()
function do in Python?- a) Counts the number of characters in a string
- b) Returns the length of an object
- c) Counts the number of items in a list
- d) All of the above
- Answer: d) All of the above
Which of the following is the correct way to declare a tuple in Python?
- a)
tuple = [1, 2, 3]
- b)
tuple = (1, 2, 3)
- c)
tuple = {1, 2, 3}
- d)
tuple = <1, 2, 3>
- Answer: b)
tuple = (1, 2, 3)
- a)
What is the output of the following code?
pythonprint("apple" == "Apple")
- a)
True
- b)
False
- c)
Error
- d)
None
- Answer: b)
False
Arithmetic Operators MCQs:
Which of the following is NOT an arithmetic operator in Python?
- a)
+
- b)
*
- c)
**
- d)
and
- Answer: d)
and
- a)
What will the following code output?
pythonprint(10 + 5)
-
a)
5
- b)
15
- c)
50
- d)
105
- Answer: b)
15
-
a)
Which operator is used for division in Python?
- a)
//
- b)
%
- c)
/
- d)
**
- Answer: c)
/
- a)
What will the following code output?
pythonprint(9 % 2)
- a)
4
- b)
1
- c)
0
- d)
9
- Answer: b)
1
- a)
Which of the following operators performs exponentiation in Python?
- a)
**
- b)
^
- c)
*
- d)
%
- Answer: a)
**
- a)
What is the result of the following expression?
pythonprint(5 * 3 - 2)
- a)
11
- b)
15
- c)
13
- d)
17
- Answer: c)
13
- a)
Which of the following operations is performed by the
//
operator?- a) Normal division
- b) Floating-point division
- c) Floor division
- d) Exponentiation
- Answer: c) Floor division
What will be the result of the following code?
pythonprint(10 // 3)
- a)
3.33
- b)
3
- c)
4
- d)
0
- Answer: b)
3
- a)
Which operator is used for calculating the remainder in Python?
- a)
/
- b)
%
- c)
//
- d)
**
-
Answer: b)
%
Additional Arithmetic Operators MCQs:
What will the following code output?
pythonprint(10 - 4 / 2)
- a)
3
- b)
8
- c)
5
- d)
12
- Answer: b)
8
- a)
Which of the following expressions is evaluated first in Python?
pythonprint(5 * (2 + 3) ** 2)
-
a)
2 + 3
- b)
5 * 2
- c)
(2 + 3) ** 2
- d) All are evaluated simultaneously
- Answer: a)
2 + 3
-
a)
What will the following code output?
pythonprint(100 // 3)
- a)
33
- b)
33.33
- c)
34
- d)
0
- Answer: a)
33
- a)
Which operator would you use to perform integer division in Python?
- a)
/
- b)
//
- c)
%
- d)
**
- Answer: b)
//
- a)
What will the following code output?
pythonprint(5 * 3 % 4)
-
a)
1
- b)
15
- c)
3
- d)
4
- Answer: a)
1
-
a)
What is the result of the following operation?
pythonprint(25 % 7)
- a)
3
- b)
4
- c)
5
- d)
6
- Answer: b)
4
- a)
Which of the following will result in a floating-point value?
- a)
10 + 5
- b)
10 / 5
- c)
10 // 5
- d)
10 % 5
- Answer: b)
10 / 5
- a)
What will the following code output?
pythonprint(2 ** 3 * 2)
- a)
8
- b)
16
- c)
32
- d)
64
- Answer: b)
16
- a)
What is the output of the following code?
pythonprint(4 + 3 * 2 ** 2)
- a)
28
- b)
16
- c)
19
- d)
25
- Answer: c)
19
- a)
Which of the following operations has the highest precedence?
- a) Addition
+
- b) Multiplication
*
- c) Exponentiation
**
- d) Modulus
%
- Answer: c) Exponentiation
**
- a) Addition
What will be the result of the following operation?
pythonprint(15 // 2 * 2)
-
a)
15
- b)
14
- c)
16
- d)
7
- Answer: b)
14
-
a)
What will the following code output?
pythonprint(-10 % 3)
- a)
2
- b)
-1
- c)
1
- d)
0
- Answer: a)
2
- a)
What is the result of this operation?
pythonprint(3 * (2 + 4) / 2)
- a)
8
- b)
6
- c)
9
- d)
12
-
Answer: c)
9
- a)
What will the following code output?
pythonprint(25 // 4 % 3)
- a)
2
- b)
1
- c)
0
- d)
4
- Answer: b)
1
- a)
Which of the following operations evaluates to
True
?pythonprint(10 == 2 * 5)
- a)
False
- b)
Error
- c)
True
- d) None of the above
- Answer: c)
True
- a)
Which of the following operations results in an integer?
- a)
5 / 2
- b)
5.0 // 2
- c)
5 // 2
- d)
5 ** 2
-
Answer: c)
5 // 2
- a)
What will the following code output?
pythonprint(5 + 10 // 3)
- a)
3
- b)
8
- c)
8.33
- d)
8.0
- Answer: b)
8
- a)
Which of the following is the correct output of the following expression?
pythonprint(20 / 3 * 2)
- a)
13.33
- b)
6.67
- c)
20
- d)
40
- Answer: a)
13.33
- a)
What is the result of the following code?
pythonprint(10 % 3 * 2 + 1)
- a)
7
- b)
5
- c)
3
- d)
1
- Answer: a)
7
- a)
Which of the following expressions evaluates to
False
?pythonprint(15 != 3 * 5)
- a)
True
- b)
False
- c)
Error
- d) None of the above
- Answer: b)
False
- a)
0 Comments
Please do note create link post in comment section