Python mcq

Python MCQs are very important for improving your Python skills. With the help of Python MCQs, you can score well in interviews and exams. These Python MCQs will be very useful for you.

Q1. Which of the following is NOT a data type?

int
float
bool
print
✅ Correct Answer: print

print is not a data type. It is a function in Python used to display output.

Q2. Which data type is used to store decimal (point) values?

int
float
bool
print
✅ Correct Answer: float

The float data type is used to store decimal (point) values. Any number that contains a decimal point is a float, such as 12.65.

Q3. Which function is used in Python to find the data type of a variable?

typeoff
type
input
output
✅ Correct Answer: type

In Python, the type() function is used to find the data type of any variable. It tells us what kind of data is stored in the variable.

Q4. What will be the output of the given code?
x = 10
print(type(x))

class 'int'
class 'float'
class 'str'
class 'bool'
✅ Correct Answer: class 'int'

In this question, the output will be class 'int' because the variable x stores an integer value (10), and the type() function is used to check its data type.

Q5. Which of the following is NOT a valid variable name?

1name
name
name_1
my_class
✅ Correct Answer: 1name

1name is not a valid variable name because variable names in Python cannot start with a number.

Q6. Identify the Bitwise Operator from the following:

is
in
&
is not
✅ Correct Answer: &

& is a Bitwise Operator. It is used to compare the binary (bits) of two numbers.

Q7. Which of the following is NOT a Python operator?

Arithmetic
Comparison
Bitwise
input
✅ Correct Answer: input

input is not an operator. It is a function used to take input from the user.

Q8. What will be the output of the given code?
x = 5
y = 10
print(x == y)

False
True
Equal
not equal
✅ Correct Answer: False

In this program, x and y are compared using the equality operator (==). Since 5 is not equal to 10, the output will be False.

Q9. What will be the output of the given code?
x = 5
x += 3
print(x)

5
3
8
10
✅ Correct Answer: 8

In this program, an assignment operator (+=) is used. It adds 3 to the value of x. So, 5 + 3 = 8, which is the output.

Q10. What is the use of the if statement?

To run a loop
To check a condition
To declare a variable
To display output
✅ Correct Answer: To check a condition

The if statement is used to check a condition. If the condition is true, the code inside the if block is executed.

Q11. Which keyword is used in Python to create a new function?

def
del
len
function
✅ Correct Answer: def

In Python, the def keyword is used to create a new function. It indicates the start of a function definition.

Q12. What should be used when we need to check more than two conditions?

For loop
if-elif-else
if
if echo
✅ Correct Answer: if-elif-else

When we need to check more than two conditions, we use if-elif-else. The code block where the condition is true gets executed.

Q13. What will be the output of the given code?
x = 15
if x > 20:
print("A")
elif x > 10:
print("B")
elif x > 5:
print("C")
else:
print("D")

A
B
C
D
✅ Correct Answer: B

The output of the given code will be B because the condition x > 10 is true. Once a condition becomes true, its block is executed and the remaining conditions are not checked.

Q14. Which of the following loop does NOT exist in Python?

While loop
for loop
do while loop
nested loop
✅ Correct Answer: do while loop

Python does not have a do while loop. It only has while loops, for loops, and nested loops.

Q15. Which type of loop is used in the given code?
for i in range(1, 4):
    for j in range(1, 4):
        print(i, j)

while loop
do while loop
for loop
nested loop
✅ Correct Answer: nested loop

The given code uses a nested loop. When one loop is inside another loop, it is called a nested loop.

Q16. What does the break statement do in Python?

Stops both types of loops
Does not stop the loop
Stops only while loops
Stops only for loops
✅ Correct Answer: Stops both types of loops

The break statement completely stops a loop. It works with both while loops and for loops.

Q17. Identify the list from the given options:

my_list = [1, 2, 3, 4]
my_list = (1, 2, 3, 4)
my_list = "1, 2, 3, 4"
none of these
✅ Correct Answer: my_list = [1, 2, 3, 4]

my_list = [1, 2, 3, 4] is a list. Lists in Python are created using square brackets [].

Q18. What will be the output of the given code?
fruits = ["Apple", "Banana", "Mango", "Orange"]
print(fruits[1])

Apple
Banana
Mango
Orange
✅ Correct Answer: Banana

According to the code, the output will be Banana because list indexing starts from 0. "Apple" is at index 0 and "Banana" is at index 1.

Q19. What is the use of append() in Python?

To delete a list
To sort a list in ascending order
To add a new item to a list
To reverse a list
✅ Correct Answer: To add a new item to a list

The append() method is used to add a new item to a list. It adds the item at the end of the list.

Q20. Identify the tuple from the given options:

t = [1, 2, 3, 4, 5]
t = (1, 2, 3, 4, 5)
t = "1, 2, 3, 4, 5"
t = {1, 2, 3, 4, 5}
✅ Correct Answer: t = (1, 2, 3, 4, 5)

t = (1, 2, 3, 4, 5) is a tuple. Tuples are created using parentheses ().

Q21. Which of the following data structures works with key-value pairs?

list
Dict
tuple
set
✅ Correct Answer: Dict

A dictionary works with key-value pairs. We can access values using their keys. In a dictionary, all keys must be unique.

Q22. Which is the correct code to perform string slicing in Python?
s = "python"

print(s[1:4])
s[0] = "h"
print(s.upper())
print(s.lower())
✅ Correct Answer: print(s[1:4])

In Python, slicing is done by using the variable name followed by square brackets with a range. The syntax s[start:end] is used, so print(s[1:4]) is correct.

Q23. What will be the output of the given code?
text = "hello python world"
print(text.upper())

Hello python world
hello python world
HELLO PYTHON WORLD
['hello', 'python', 'world']
✅ Correct Answer: HELLO PYTHON WORLD

upper() is a string method that converts all characters into uppercase. Therefore, the output will be HELLO PYTHON WORLD.

Q24. What will be the output of the given code?
name = "Ram"
age = 20
print(f"My name is {name} and I am {age} years old")

f"My name is {name} and I am {age} years old"
My name is Ram and I am 20 years old
f"My name is name and I am age years old"
none of these
✅ Correct Answer: My name is Ram and I am 20 years old

The output will be My name is Ram and I am 20 years old because an f-string is used. f-strings allow variables to be directly included and displayed inside a string.

Q25. Why are functions created in Python?

To repeat code
To reuse code
To create variables
To generate errors
✅ Correct Answer: To reuse code

Functions in Python are used to reuse code. When we need the same functionality again, we can call the function instead of writing the same code repeatedly.