Lists
- Lists are ordered collections of data items.
- They store multiple items in a single variable.
- List items are separated by commas and enclosed within square brackets
[]. - Lists are changeable, meaning we can alter them after creation.
Example 1:
lst1 = [1, 2, 2, 3, 5, 4, 6]
lst2 = ["Red", "Green", "Blue"]
print(lst1)
print(lst2)Output:
[1, 2, 2, 3, 5, 4, 6]
['Red', 'Green', 'Blue']Example 2:
details = ["Abhijeet", 18, "FYBScIT", 9.8]
print(details)Output:
['Abhijeet', 18, 'FYBScIT', 9.8]As we can see, a single list can contain items of different data types, such as strings, integers, and floats.