Computer >> Computer tutorials >  >> Programming >> Python

How can I convert Python strings into tuple?


Python’s built-in function tuple() converts any sequence object to tuple. If it is a string, each character is treated as a string and inserted in tuple separated by commas.

>>> string="Tutorialspoint"
>>> tuple(string)
('T', 'u', 't', 'o', 'r', 'i', 'a', 'l', 's', 'p', 'o', 'i', 'n', 't')

Any non-sequence object as argument results in TypeError.