Python Tuple Merge MethodPython Functions

Difficulty Level:
Difficulty Level:

In Python, the ‘+’ operator can be used to connect two or multiple tuples.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

tuple1 = ('Google', 'Baidu', 'Apple')
tuple2 = ('eBay', 'Facebook','Amazon')
tuple3 = tuple1 + tuple2

print('tuple1 is: ', tuple1)
print('tuple2 is: ', tuple2)
print('tuple1 + tuple2 is: ', tuple3)

Output:

tuple1 is:  ('Google', 'Baidu', 'Apple')
tuple2 is:  ('eBay', 'Facebook', 'Amazon')
tuple1 + tuple2 is:  ('Google', 'Baidu', 'Apple', 'eBay', 'Facebook', 'Amazon')

Syntax

tuple1 + tuple2

Parameters

tuple1 and tuple2 are two tuples.

Return Value

A new tuple consisted of two tuples.

Advertisement

© 2021 Pythonexample.org, all rights reserved. Privacy Policy | Contact Us