How to Use List Multiply Method in PythonPython Basics


The function of the operator * is used to enlarge the list.

Example

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

list1 = ['A','B','C']
print(list1)

list2=list1*3
print("the list2  is: ",list2)

Output:

['A', 'B', 'C']
the list2  is:  ['A', 'B', 'C', 'A', 'B', 'C', 'A', 'B', 'C']

Syntax

list1*n

Parameters

Name Description
list1 A list
n A number

Return Value

It returns a new list.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us