How to Join Tuples in Python

In this article, you will learn how to join tuples in Python. Let’s say you have 2 tuples. Join Tuples in Python In order to…

The post How to Join Tuples in Python appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli

In this article, you will learn how to join tuples in Python.

Let’s say you have 2 tuples.

# A tuple named 'a' with value ("Red", "Green", "Blue")
a = ("Red", "Green", "Blue")

# A tuple named 'b' with value ("Cyan", "Yellow", "Magenta")
b = ("Cyan", "Yellow", "Magenta") 

Join Tuples in Python

In order to join tuples, you can use the zip() method and tuple() method.

# A tuple named 'a' with value ("Red", "Green", "Blue")
a = ("Red", "Green", "Blue")

# A tuple named 'b' with value ("Cyan", "Yellow", "Magenta")
b = ("Cyan", "Yellow", "Magenta")

# Display tuples in readable format
print(tuple(zip(a, b)))
# (('Red', 'Cyan'), ('Green', 'Yellow'), ('Blue', 'Magenta'))

Note: The zip() method functions by creating a series of tuples from each element in both supplied iterables. The tuple() method functions by creating a tuple from the supplied iterable.

The post How to Join Tuples in Python appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli


Print Share Comment Cite Upload Translate Updates
APA

Ariessa Norramli | Sciencx (2021-02-26T13:49:48+00:00) How to Join Tuples in Python. Retrieved from https://www.scien.cx/2021/02/26/how-to-join-tuples-in-python/

MLA
" » How to Join Tuples in Python." Ariessa Norramli | Sciencx - Friday February 26, 2021, https://www.scien.cx/2021/02/26/how-to-join-tuples-in-python/
HARVARD
Ariessa Norramli | Sciencx Friday February 26, 2021 » How to Join Tuples in Python., viewed ,<https://www.scien.cx/2021/02/26/how-to-join-tuples-in-python/>
VANCOUVER
Ariessa Norramli | Sciencx - » How to Join Tuples in Python. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/26/how-to-join-tuples-in-python/
CHICAGO
" » How to Join Tuples in Python." Ariessa Norramli | Sciencx - Accessed . https://www.scien.cx/2021/02/26/how-to-join-tuples-in-python/
IEEE
" » How to Join Tuples in Python." Ariessa Norramli | Sciencx [Online]. Available: https://www.scien.cx/2021/02/26/how-to-join-tuples-in-python/. [Accessed: ]
rf:citation
» How to Join Tuples in Python | Ariessa Norramli | Sciencx | https://www.scien.cx/2021/02/26/how-to-join-tuples-in-python/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.