Important Notice:

Creating a List

Creating a List

17 views 2 min read
Creating a List :-

Python में List create करने का अर्थ है एक ऐसा collection बनाना जिसमें हम multiple elements या values को एक ही variable में store कर सकें।
English
Creating a List in Python means creating a collection in which we can store multiple elements or values in a single variable.

1. Creating an Empty List :-

जिस List में शुरुआत में कोई element नहीं होता, उसे Empty List कहा जाता है।
English:
An empty list is a list that contains no elements. It can be created using empty square brackets [].

Example:-

numbers = []

print(numbers)

Output:-

[]

बाद में इसमें elements add किए जा सकते हैं।

numbers = []

numbers.append(10)
numbers.append(20)
numbers.append(30)

print(numbers)

Output:-

[10, 20, 30]

 

2. Creating a List with Integer Values :-

List में integer values को store किया जा सकता है।
English:
A list can contain multiple integer values.

Example:-

numbers = [10, 20, 30, 40, 50]

print(numbers)

Output:-

[10, 20, 30, 40, 50]

यहाँ List में पाँच integer elements हैं।

 

3. Creating a List with String Values :-

List में strings को भी store किया जा सकता है।
English:
A list can contain multiple string values.

Example:-

names = ["Rahul", "Amit", "Neha", "Priya"]

print(names)

Output:-

['Rahul', 'Amit', 'Neha', 'Priya']

यहाँ सभी elements String हैं।


4. Creating a List with Different Data Types :-

Python List में different data types के elements को एक साथ store किया जा सकता है।
English:
A Python list can contain elements of different data types.

Example:-

student = ["Rahul", 20, 85.5, True]

print(student)

Output:-

['Rahul', 20, 85.5, True]

यहाँ:

"Rahul" → String
20 → Integer
85.5 → Float
True → Boolean

 

5. Creating a List with Duplicate Values :-

List में एक ही value को multiple times store किया जा सकता है।
English:
Lists allow duplicate elements.

Example:-

numbers = [10, 20, 10, 30, 10]

print(numbers)

Output:-

[10, 20, 10, 30, 10]

यहाँ 10 तीन बार मौजूद है।

 

Related Notes