Example:
tuple = ("python", "includehelp", 43, 54.23)
Create Tuple from String and List in Python
In this article, we will be creating a Python program to create a new tuple of the given string and list in python.
Input:
['Python', 'Programming', 'language']
'Tutorial'
Output:
('Python', 'Programming', 'language', 'Tutorial')
This task can be performed by adding the values of both collections into a tuple. In Python, there are multiple methods to perform the task.
Method 1:
One method to solve the problem is by adding the string to the original list as a list and then converting the addition list to a tuple using the tuple() method and print the result.
Output:
Method 2:
Another method by performing the tuple conversion of both the collections i.e. string and list. And then concatenate the two tuples.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer