How to convert Python list, tuples, strings to each other…
1 min readDec 6, 2017
There are three built-in functions in Python : lists, tuples, and strings. The three functions, str (), tuple (), and list (), convert to each other using the following example:
>>> s = ‘123456’
>>> list(s)
[‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’]
>>> tuple(s)
(‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’)
>>> tuple(list(s))
(‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’)
>>> list(tuple(s))
[‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’]
>>> “”.join(tuple(s))
‘123456’
>>> “”.join(list(s))
‘123456’
>>> str(tuple(s))
“(‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’)”
>>> str(list(s))
“[‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’]”