Sobes.tech
Junior — Middle

Is it allowed to store elements of different data types in the same list in Python?

sobes.tech AI

Answer from AI

Yes, in Python, a list (list) can contain elements of different data types simultaneously. This is due to Python's dynamic typing and the fact that lists store references to objects, not the data itself.

Example:

mixed_list = [1, "string", 3.14, True, [1, 2, 3]]
print(mixed_list)

Here, the list contains an integer, a string, a float, a boolean, and another list.