4.14: Converting Between Lists and Tuples

Making Games with Python and Pygame · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC-SA 3.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    4.14: Converting Between Lists and Tuples

    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)
    >>> 

    This page titled 4.14: Converting Between Lists and Tuples was last modified on Fri, 01 Nov 2019 01:24:57 GMT and is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Al Sweigart via source content that was edited to the style and standards of the LibreTexts platform.