Answers | Python Scripting & Automation Prep.
Questions 1-20: Python Fundamentals & Data Types
Question 1
Which Python data type is immutable and ordered?
A) List
B) Dictionary
C) Tuple
D) Set
Answer: C
Rationale: Tuples are immutable (cannot be changed after creation) and ordered
sequences. Lists are mutable and ordered, dictionaries are mutable key-value
pairs, and sets are unordered and mutable. The immutability of tuples makes
them hashable and usable as dictionary keys .
Question 2
What is the output of print(type([]))?
,A) <class 'tuple'>
B) <class 'list'>
C) <class 'dict'>
D) <class 'set'>
Answer: B
Rationale: [] creates an empty list. The type() function returns the class type of
the object. Lists are ordered, mutable collections that allow duplicate elements .
Question 3
Which collection type automatically eliminates duplicate values?
A) List
B) Tuple
C) Dictionary
D) Set
Answer: D
Rationale: Sets are unordered collections that contain only unique items. Any
duplicate values added to a set are automatically eliminated. This makes sets
,particularly useful for filtering unique entries, such as extracting unique IP
addresses from log files .
Question 4
What is the result of int(13.9) in Python?
A) 14
B) 13.9
C) 13
D) Error
Answer: C
Rationale: When converting from a floating-point number to an integer, Python
truncates (removes) the decimal part—it does NOT round. int(13.9) returns 13. If
rounding is needed, use the round() function, which would return 14 .
Question 5
Which statement correctly creates a dictionary?
A) devices = ('Router1', '192.168.1.2')
, B) devices = ['Router1' = '192.168.1.2']
C) devices = {'Router1': '192.168.1.2', 'Switch2': '10.0.0.2'}
D) devices = {'Router1', 'Switch2'}
Answer: C
Rationale: Dictionaries in Python use curly braces {} with key-value pairs
separated by colons :. Option A creates a tuple, Option B uses incorrect syntax,
and Option D creates a set .
Question 6
What does the len() function return when called on a string?
A) The number of words in the string
B) The number of characters in the string
C) The memory size of the string
D) The number of unique characters
Answer: B
Rationale: len() returns the number of characters (including spaces and special
characters) in a string. For strings, it counts each character individually .