Shawn Scott
PRO
last year
Shawncountry asked

What is the syntax difference between a list and a tuple in Python?

Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Shawn,

The main difference is in how they’re defined:

  • List → uses square brackets []

    my_list = [1, 2, 3]
    
  • Tuple → uses parentheses ()

    my_tuple = (1, 2, 3)
    

If you're creating a tuple with just one item, you need a comma — otherwise, Python won’t treat it as a tuple:

single_item = (1)     # This is just the number 1  
single_item_tuple = (1,)  # This is a tuple with one item

Lists don’t need a comma for single items, and you can freely change (mutate) them — unlike tuples, which are immutable.

If you have more questions, I am here to help.

Python
This question was asked as part of the Getting started with Python course.