Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

Operator *

Multiplies numbers or repeats a sequence an integral number of times.

Version: Python 3.14; repository image, production runtime not attested

Syntax

left * right

Multiplies numbers or repeats a sequence an integral number of times.

Use numeric multiplication for scaling and sequence repetition for creating a specified number of copies of a sequence’s references. A negative sequence count gives an empty sequence.

A repeat count must support the integer-index protocol. Repeating a list containing a mutable object shares that object between positions, so later mutations can appear in several places.

Repeating a sequence zero times produces an empty sequence of the same type.

Syntax

left * right

__mul__, __rmul__ · TypeError

Worked example

[1] * 3 → [1, 1, 1]
"ab" * -1 → ""
"ab" * 1.5 → TypeError

Examples

print(7 * -3)
print(list("ab" * 0))

Result

-21
[]

Repeating a sequence zero times produces an empty sequence of the same type.

Sources