There are 4 built-in data types available in python. Lets learn about them
List:
Lists are used to store multiple items in a single variable.
List items are ordered, changeable, and allow duplicate values. List items are indexed, the first item has index [0], the second item has index [1] etc.
Python Tuples:
Tuples are used to store multiple items in a single variable. A tuple is a collection which is ordered and unchangeable.
Tuples are unchangeable, meaning that we cannot change, add or remove items after the tuple has been created.
Since tuples are indexed, they can have items with the same value:
thistuple = ("apple", "banana", "cherry", "apple", "cherry")
print(thistuple)
Python Sets:
A set is a collection which is unordered, unchangeable*, and unindexed.
Set items are unordered, unchangeable, and do not allow duplicate values.
thisset = {"apple", "banana", "cherry"}
print(thisset)
Sets cannot have two items with the same value. Duplicate values will be ignored:
Comments
Post a Comment