4 built-in data types
In Python, lists, sets, tuples, and dictionaries are used to store collections of data. Each has different properties and use cases.
- set: an ordered, immutable collection that allows duplicate values.
It can contain different data types:
✅ numbers, strings, booleans, lists, dictionaries, and even other tuples.
❌ cannot directly contain mutable objects like lists as elements.
Use tuples when data should not be modified. Tuples are faster than lists.
employee = ('John Doe', 30, 5.9)
employee[0] # 'John Doe'
for i in employee:
print(i) # John Doe
# 30
# 5.9
name, age, height = employee
print(f"{name.title()} is {age} years old and {height}\" tall.") # John Doe is 30 years old and 5.9" tall.
# tuples are immutable
employee[0] ='Jack Smith' # error message