Search⌘ K

Tuples, Sets and Booleans

Explore the properties of tuples, sets, and booleans in Python. Understand how tuples are immutable sequences, sets enforce uniqueness, and booleans represent true or false values. Learn their key differences compared to lists and dictionaries to manage data effectively.

Tuples

Tuples have the following properties:

  • They are sequences, like lists.
  • They are immutable, like strings, and can’t be reassigned.
  • They’re used to represent a fixed collection of items.
  • They’re coded in parentheses () instead of square brackets.

Let’s create a tuple and see its response to some operations.

Python 3.5
# Creating a tuple "t"
t = (3,4,5)
# we can grab any element using index
print("Element from tuple : {}".format(t[0]))
...