Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Python: Creating a tuple

📅 2012-Apr-24 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ python, tuple ⬩ 📚 Archive

# Empty tuple
t = ()
t = tuple()

# Tuple with one item
t = (99,)
t = ("snake",)
t = tuple([99])
t = tuple(["snake"])

# Tuple with many items
t = (99,"snake")
t = tuple([99,"snake"])

# Tuple with nested items
t = ((99,100),"snake")

# Works in many places, *not* everywhere
t = 99,
t = 99, "snake"

Tried with: Python 3.2.2