Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 23596

Python Morsels: How to make a tuple

$
0
0

Tuples are technically just immutable lists, but by convention we tend to use tuples and lists for quite different purposes.

Making tuples in Python

Here's a list named coordinates:

>>> coordinates=[3,4,5]>>> type(coordinates)<class 'list'>

It's a list because we used square brackets ([...]) to make it.

If we had used parentheses ((...)) instead, we would've made a tuple:

>>> coordinates=(3,4,5)>>> type(coordinates)<class 'tuple'>>>> coordinates(3, 4, 5)

Tuples are like lists, but immutable

Like a list, a tuple …

Read the full article: https://www.pythonmorsels.com/how-to-make-a-tuple/


Viewing all articles
Browse latest Browse all 23596

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>