How can I convert Python strings into tuple?

PythonServer Side ProgrammingProgramming

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.


raja
Published on 06-Feb-2018 11:34:22
Advertisements