Junior — Middle
Is it possible to use lists in Python to store elements of different data types simultaneously?
sobes.tech AI
Answer from AI
Yes, in Python, lists can contain elements of different data types simultaneously. This is due to the language's dynamic typing and the fact that lists are ordered, mutable collections of objects.
Example:
mixed_list = [1, "string", 3.14, True, [1, 2, 3]]
print(mixed_list)
# Output: [1, 'string', 3.14, True, [1, 2, 3]]
Thus, a single list can store numbers, strings, boolean values, other lists, and any objects.