Python_Expanded_Data_Types
Python_Expanded_Data_Types
**5. Lists**:
Lists are ordered, mutable collections of items.
They can contain elements of different types.
Example:
numbers = [1, 2, 3, 4]
numbers.append(5)
print(numbers)
**6. Tuples**:
Tuples are ordered, immutable collections.
They are faster than lists and used for fixed collections.
Example:
coordinates = (10.0, 20.0)
print(coordinates)
**7. Sets**:
Sets are unordered collections of unique elements.
Used to perform set operations like union, intersection.
Example:
unique_numbers = {1, 2, 2, 3}
print(unique_numbers) # Outputs {1, 2, 3}
**Type Casting**:
You can convert data from one type to another using type casting functions:
- int(): Converts to integer
- float(): Converts to float
- str(): Converts to string
- bool(): Converts to boolean
Example:
x = int('5') # Converts string to int
print(x + 2)