python

Convert comma separated string values to tuple python

you can use the .split() function to convert comma-separated values string to list and then use the tuple() method to convert the list to a tuple.

fruits = "Apple,Mango,Orange"
fruit_list = fruits.split(',')
print( tuple(fruit_list) )
# -> ('Apple', 'Mango', 'Orange')
Output
('Apple', 'Mango', 'Orange')
Was this helpful?