Important Notice:

List Repetition

List Repetition

10 views 1 min read
List Repetition :-
Python में List Repetition का अर्थ है किसी List के elements को एक से अधिक बार दोहराना (repeat करना)। List Repetition के लिए * multiplication operator का उपयोग किया जाता है।

English

List Repetition means repeating the elements of a list multiple times. The * multiplication operator is used for list repetition.

Syntax:-

result = list * number

यहाँ number बताता है कि List को कितनी बार repeat करना है।

Example:-
numbers = [10, 20, 30]

result = numbers * 3

print(result)

Output:-

[10, 20, 30, 10, 20, 30, 10, 20, 30]

Because:-

यहाँ:

numbers → [10, 20, 30]

numbers * 3 का अर्थ है List को 3 बार repeat करना।

इसलिए:

[10, 20, 30] + [10, 20, 30] + [10, 20, 30]

→ [10, 20, 30, 10, 20, 30, 10, 20, 30]

English

Here, numbers * 3 repeats the entire list three times.

Example with String List :-
 
colors = ["Red", "Blue"]

print(colors * 3)

Output:-

['Red', 'Blue', 'Red', 'Blue', 'Red', 'Blue']

यहाँ ["Red", "Blue"] को तीन बार repeat किया गया है।

Repetition with Zero :-

यदि List को 0 से multiply किया जाए, तो एक Empty List प्राप्त होती है।

numbers = [10, 20, 30]

print(numbers * 0)

Output:-

[]
 
Repetition with One :-

यदि List को 1 से multiply किया जाए, तो List में कोई अतिरिक्त repetition नहीं होती।

numbers = [10, 20, 30]

print(numbers * 1)

Output:-

[10, 20, 30]
Important Point :-

List Repetition में:

* operator → List के elements को specified number of times repeat करता है।

Example:

[1, 2] * 4

Output:

[1, 2, 1, 2, 1, 2, 1, 2]
List Concatenation और List Repetition में अंतर :-

List Concatenation → + operator का उपयोग करके Lists को जोड़ना।

List Repetition → * operator का उपयोग करके List को repeat करना।

Related Notes