0% found this document useful (0 votes)
6 views7 pages

Python questions

The document contains 20 multiple-choice questions (MCQs) about Python programming, categorized by difficulty: 10 easy, 5 medium, and 5 hard. Each question includes four answer options and the correct answer is provided. The topics covered include syntax, variable declaration, data types, and modes of execution in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views7 pages

Python questions

The document contains 20 multiple-choice questions (MCQs) about Python programming, categorized by difficulty: 10 easy, 5 medium, and 5 hard. Each question includes four answer options and the correct answer is provided. The topics covered include syntax, variable declaration, data types, and modes of execution in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Here are 20 MCQs based on the provided topics, categorized by difficulty:

Easy (10 Questions):

1. What is the correct syntax to print "Hello, World!" in Python?

A. echo "Hello, World!"

B. print("Hello, World!")

C. console.log("Hello, World!")

D. printf("Hello, World!")

Answer: B

2. What is the extension of a Python file?

A. .py

B. .python

C. .pt

D. .txt

Answer: A

3. Which of the following is not a Python keyword?

A. for

B. while

C. loop

D. if

Answer: C

4. Which mode allows you to execute Python statements line by line?


A. Script Mode

B. Interactive Mode

C. Batch Mode

D. Command Mode

Answer: B

5. Which of the following is a valid Python identifier?

A. 1variable

B. variable_1

C. variable-1

D. variable 1

Answer: B

6. What is the output of the following code?

print("Hello" + " World")

A. Hello + World

B. Hello World

C. HelloWorld

D. Error

Answer: C

7. Which of the following is a punctuator in Python?

A. +

B. #
C. ;

D. .

Answer: D

8. What type of value is "123" in Python?

A. Integer

B. Float

C. String

D. Boolean

Answer: C

9. What is the purpose of the # symbol in Python?

A. To define a function

B. To indicate a comment

C. To start a loop

D. To terminate a statement

Answer: B

10. In Python, what is the correct way to declare a variable?

A. int a = 10

B. var a = 10

C. a = 10

D. declare a = 10

Answer: C
---

Medium (5 Questions):

11. What is the output of the following code?

a=5
b = "5"
print(a + int(b))

A. 55

B. 10

C. 5 5

D. Error

Answer: B

12. What is the correct way to execute a Python script in the command line?

A. python script.py

B. run script.py

C. execute script.py

D. start script.py

Answer: A

13. Which of the following is not considered a Python token?

A. Keyword

B. Identifier

C. Operator
D. Library

Answer: D

14. What is the output of the following code?

x = 10
y=x
x = 20
print(y)

A. 10

B. 20

C. 30

D. Error

Answer: A

15. In Python, x = 10 assigns the value 10 to x. In this statement, what is x considered?

A. r-value

B. l-value

C. Constant

D. Operator

Answer: B

---

Hard (5 Questions):

16. What is the output of the following code?

x = 10
y = "20"
print(x + y)

A. 30

B. 1020

C. Error

D. None

Answer: C

17. Which of the following is not a valid Python variable name?

A. var1

B. _variable

C. 2var

D. var_2

Answer: C

18. What will be the output of the following code?

a = "Hello"
print(a[1])

A. H

B. e

C. l

D. Error

Answer: B

19. Which of the following statements is true regarding the interactive mode and script mode
in Python?
A. Script mode is used for testing code line by line.

B. Interactive mode saves the code in a .py file.

C. Interactive mode is suitable for quick testing.

D. Script mode displays immediate output of statements.

Answer: C

20. What will be the output of the following code?

x=5
y = 10
print(x == y)

A. True

B. False

C. None

D. Error

Answer: B

You might also like