ScanSkill

tuple

This tuple() function is a sequence constructor which returns a tuple i.e. it creates a tuple.

Syntax

tuple(iterable)

Here,

  • iterable: Optional. Any iterator object(or list, range, etc.)

Examples

  • Create tuple using tuple()
>>> tuple((1, 2))
(1, 2)
>>> tuple('foo')
('f', 'o', 'o')
>>> tuple((1, 2))
(1, 2)
>>> tuple({1, 2})
(1, 2)
>>> tuple({'a':1, 'b':2})
('a', 'b')
>>> tuple([1, 2])
(1, 2)
>>> tuple()
()
>>> tuple(iter([1, 2]))
(1, 2)