Converting a tuple and string to list

list and tuple are sequences in python. There are composite data types. String is a text type. list is commonly used data type in python and if a programmer wants to convert tuple and string types to list, follow the below steps.

#a tuple is declared below
sites = "embeddeddesignblog","py-programmers","way2know"

#a string is declared below
str = "This is a blog"

print(list(sites))
print(list(str))

The above program outputs,
['embeddeddesignblog', 'py-programmers', 'way2know']
['T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 'b', 'l', 'o', 'g']

We can see that tuple and string are converted to tuple.

list() function is used for conversion to tuple.

Post a Comment

0 Comments