Skip to main content
Engineering LibreTexts

4.14: Converting Between Lists and Tuples

  • Page ID
    14447
  • You can convert between list and tuple values just like you can convert between string and integer values. Just pass a tuple value to the list() function and it will return a list form of that tuple value. Or, pass a list value to the tuple() function and it will return a tuple form of that list value. Try typing the following into the interactive shell:

    >>>  spam = (1, 2, 3, 4)
    >>>  spam = list(spam) >>> spam
    [1, 2, 3, 4]
    >>> spam = tuple(spam) >>> spam
    (1, 2, 3, 4)
    >>>