Python for IT Automation Practice Exam
With correct answers and rationale
updated 2026 graded a+
1. What is the correct way to assign the string "hello" to a variable named greeting?
A. string greeting = "hello"
B. greeting <- "hello"
C. greeting = "hello"
D. var greeting = "hello"
Answer: C
Rationale: Python uses = for assignment and does not require variable type declarations.
2. Which data type is immutable in Python?
A. List
B. Dictionary
C. Set
D. Tuple
Answer: D
Rationale: Tuples cannot be modified after creation, while lists, dictionaries, and sets are mutable.
3. What will print(type(5)) display?
A. <type int>
B. <class 'int'>
C. int
D. integer
Answer: B
,Rationale: In Python 3, type(5) returns <class 'int'>.
4. Which of the following creates a list?
A. {1, 2, 3}
B. (1, 2, 3)
C. [1, 2, 3]
D. <1, 2, 3>
Answer: C
Rationale: Square brackets define a list in Python.
5. What is the result of 3 + 2 * 4?
A. 20
B. 11
C. 14
D. 24
Answer: B
Rationale: Multiplication happens before addition, so 2 * 4 = 8, then 3 + 8 = 11.
6. Which statement is used to make decisions in Python?
A. switch
B. select
C. if
D. case
Answer: C
Rationale: Python uses if, elif, and else for conditional logic.
7. What is the output of print("7" + "3")?
A. 10
, B. 73
C. 7 3
D. Error
Answer: B
Rationale: Both operands are strings, so + concatenates them.
8. Which loop is best when you know how many times you want to repeat?
A. while
B. for
C. repeat
D. do-while
Answer: B
Rationale: A for loop is commonly used when iterating over a known sequence or range.
9. What does len("python") return?
A. 5
B. 6
C. 7
D. Error
Answer: B
Rationale: The string "python" contains 6 characters.
10. Which of the following is a valid Python comment?
A. // comment
B. <!-- comment -->
C. # comment
D. ** comment **
With correct answers and rationale
updated 2026 graded a+
1. What is the correct way to assign the string "hello" to a variable named greeting?
A. string greeting = "hello"
B. greeting <- "hello"
C. greeting = "hello"
D. var greeting = "hello"
Answer: C
Rationale: Python uses = for assignment and does not require variable type declarations.
2. Which data type is immutable in Python?
A. List
B. Dictionary
C. Set
D. Tuple
Answer: D
Rationale: Tuples cannot be modified after creation, while lists, dictionaries, and sets are mutable.
3. What will print(type(5)) display?
A. <type int>
B. <class 'int'>
C. int
D. integer
Answer: B
,Rationale: In Python 3, type(5) returns <class 'int'>.
4. Which of the following creates a list?
A. {1, 2, 3}
B. (1, 2, 3)
C. [1, 2, 3]
D. <1, 2, 3>
Answer: C
Rationale: Square brackets define a list in Python.
5. What is the result of 3 + 2 * 4?
A. 20
B. 11
C. 14
D. 24
Answer: B
Rationale: Multiplication happens before addition, so 2 * 4 = 8, then 3 + 8 = 11.
6. Which statement is used to make decisions in Python?
A. switch
B. select
C. if
D. case
Answer: C
Rationale: Python uses if, elif, and else for conditional logic.
7. What is the output of print("7" + "3")?
A. 10
, B. 73
C. 7 3
D. Error
Answer: B
Rationale: Both operands are strings, so + concatenates them.
8. Which loop is best when you know how many times you want to repeat?
A. while
B. for
C. repeat
D. do-while
Answer: B
Rationale: A for loop is commonly used when iterating over a known sequence or range.
9. What does len("python") return?
A. 5
B. 6
C. 7
D. Error
Answer: B
Rationale: The string "python" contains 6 characters.
10. Which of the following is a valid Python comment?
A. // comment
B. <!-- comment -->
C. # comment
D. ** comment **