Python Tuple Multiplication MethodPython Functions

Difficulty Level:
Difficulty Level:

The operator multiplication (*) can be used to expand a tuple many times.

Example

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

tuple1 = ('Google', 'Baidu', 'Apple')
print('Tuple-1 is: ', tuple1)
tuple2 = tuple1 * 3
print('Tuple-1 * 3 is: ', tuple2)

Output:

Tuple-1 is:  ('Google', 'Baidu', 'Apple')
Tuple-1 * 3 is:  ('Google', 'Baidu', 'Apple', 'Google', 'Baidu', 'Apple', 'Google', 'Baidu', 'Apple')

Syntax

tuple * n

Parameters

Name Description
tuple A tuple
n A number, the times of expanding tuples

Return Value

It generates a new tuple that is expanded result of the input tuple.

Advertisement

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