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?
Similar Posts
- [Python] Slice of tuple
- Access items of tuple in Python
- Convert all string values in a list to integers using python
- Convert all string characters to lowercase in python
- Convert JSON string to Python collections - like list, dictionaries
- Convert Python Collections - List, Dict to JSON String
- Convert multiple spaces of a string to single space in python [with and without regex]