codegurukool.com · Free coding tutorials & online compiler

Home › Python Tutorial › Python tuples and sets

Python tuples and sets

Fixed sequences and unique values.

A tuple uses round brackets and cannot be changed. A set uses curly braces, keeps only unique values and supports maths operations such as union (|).

Example code

t = (1, 2, 3)
print(t[1])
s = {1, 2, 2, 3}
s.add(4)
print(sorted(s))
print({1, 2} | {2, 3})

Run this code in the online editor

← Python listsPython dictionaries →