
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create a tuple from string and list in Python
When it is required to create a tuple from a string and a list, the tuple method can be used.
A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).
Below is a demonstration of the same −
Example
my_list_1 = ['Hey', 'there', 'How', 'are', 'you'] my_list_2 = 'Jane' print("The first list is :") print(my_list_1) print("The string is :") print(my_list_2) my_result = tuple(my_list_1 + [my_list_2]) print("The aggregated tuple is : ") print(my_result)
Output
The first list is : ['Hey', 'there', 'How', 'are', 'you'] The string list is : Jane The aggregated tuple is : ('Hey', 'there', 'How', 'are', 'you', 'Jane')
Explanation
- A list is created and displayed on the console.
- Another string is defined.
- The tuple and '[]' are used to aggregate the list and string.
- The final output is displayed on the console.
- Related Questions & Answers
- How to create a tuple from a string and a list of strings in Python?
- Create Unit Tuple from List in Java
- Create Pair Tuple from List in Java
- Create Quartet Tuple from List in Java
- Create Quintet Tuple from List in Java
- Create Septet Tuple from List in Java
- Create Triplet Tuple from List in Java
- Create Ennead Tuple from a List collection in Java
- Create Decade Tuple from a List collection in Java
- Create LabelValue Tuple from a List collection in Java
- Create Octet Tuple from a List collection in Java
- Create KeyValue Tuple from a List collection in Java
- Create a list of tuples from given list having number and its cube in each tuple using Python
- Extract digits from Tuple list Python
- How do we create python string from list?
Advertisements