Understanding Mutability with Data Structures
Given the code snippet fruits = ['apple', 'banana', 'cherry'], which of the following will change the first element of the list to 'grape'?
- A. fruits[0] = 'grape'
- B. fruits(0) = 'grape'
- C. fruits{'0'} = 'grape'
- D. set fruits[0] = grape
- E. fruits[1] = 'grape'
Tuple Characteristics
Which statement best describes a tuple in Python compared to a list?
- A. A tuple is mutable and can be changed after creation.
- B. A tuple is immutable and does not allow item modification.
- C. A tuple only stores integers.
- D. A tuple uses curly braces for its definition.
- E. A tuple automatically sorts its elements.
Python Variable Assignment
If you execute the code: a = 10; a = 'ten'; what will be the type and value of 'a' after both statements run?
- A. Integer, 10
- B. String, 'ten'
- C. Float, 10.0
- D. Boolean, False
- E. Tuple, (10, 'ten')
Identifying Correct Data Type Usage
Suppose you want to store unique, unordered items in a variable. Which Python data type is MOST appropriate?
- A. list
- B. dict
- C. set
- D. tuple
- E. str
Interpreted Languages and Python
Which statement accurately explains what it means for Python to be an interpreted language?
- A. Python code is always compiled directly into machine code.
- B. Python executes scripts line by line, making real-time debugging possible.
- C. Python requires all code to be written before running any part of it.
- D. Python cannot run on multiple operating systems.
- E. Python interprets comments as executable statements.