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’]”

Leave a Reply

Your email address will not be published. Required fields are marked *