6 of 151 menu

The tuple function

The tuple function creates a new tuple from the object specified in the parameter.

Syntax

tuple(the object from which we create a tuple)

Example

Let's make a tuple using the tuple function:

txt = 'abcde' tlp = tuple(txt) print(tlp)

Result of code execution:

('a', 'b', 'c', 'd', 'e')

Example

Now let's make a dictionary from the number:

num = 1234 tlp = tuple(num) print(tlp)

After executing the code, the function will return us an error, since the number is not an iterable object:

TypeError: 'int' object is not iterable

Example

Let's use the tuple function to make a tuple from a list:

lst = ['a', 'b', 'c', 'd'] tlp = tuple(lst) print(tlp)

Result of code execution:

('a', 'b', 'c', 'd')

See also

  • function list,
    which creates a list
  • function dict,
    which creates a dictionary
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline