List
पाइथन मे list , array की तरह होते है | list जो है वो mutable(changeable) होता है |
एक सिंगल list डाटा टाइप जैसे int , string और ऑब्जेक्ट को contain करके रखता है|
list , stacks और queues को implement करने का एक उपयोगी तरीका है |
पाइथन list मे जो elements होते है उन्हें [items] कहते है |
Creating List
लिस्ट के item को हम square brackets([ ]) के अंदर लिख़ते है और प्रत्येक item को comma(,) से separate किया जाता है |
syntax :- < listname > = [item1, item2, item3,________,item n]
जैसे की :-
# blank list
list = [ ]
#string list
list1 = ["hello","python","india"]
#Integer List
list2 = [15, 24, 38, 54]
#Float List
list3 = [5.5, 4.8, 9.8, 4.4, 5.7];
#Mixed Data Types List
list4 = [1, 28, "python", 45.5];
#Nested List
list5 = [21, [15, 2], 4.5]
Indexing of a list
Forward indexing जीरो ( 0 ) से शुरू होती है जबकि backward indexing -1 से शुरू होती है|

Python list operation
Add the python lists
list1 = [15,56,35]
list2 = [89,65,"hello",68.78]
list = list1+list2
print (list)
output :-
[15, 56, 35, 89, 65, 'hello', 68.78]
Python repeating lists
list = ["python",79,"hello",68.78]
print (list*2)
output :-
['python', 79, 'hello', 68.78, 'python', 79, 'hello', 68.78]
Python lists slicing
list = ["python",79,"hello",68.78,95,36.2,"program"]
print (list[0:4])
# output :- ['python', 79, 'hello', 68.78]
print (list[4])
# output :- 95
list [2] = "information"
print (list )
# output :- ['python', 79, 'information', 68.78, 95, 36.2, 'program']
print (list[ :-1])
# output :- ['python', 79, 'information', 68.78, 95, 36.2]
print (list[-3:-1])
# output :- [95, 36.2]
Python updating list
List मे particular किसी index की वैल्यू को change करना और update करना |
list = ["python",79,"hello",68.78,95,36.2,"program"]
list [4] = "technology"
print (list)
output :- ['python', 79, 'hello', 68.78, 'technology', 36.2, 'program']
Deleting element
list = ["python",79,"hello",68.78,95,36.2,"program"]
del list[2]
print(list)
output :-
['python', 79, 68.78, 95, 36.2, 'program']
List Methods
Method | Description |
---|---|
append() | Adds an element at the end of the list |
clear() | Removes all the elements from the list |
copy() | Returns a copy of the list |
count() | Returns the number of elements with the specified value |
extend() | Add the elements of a list (or any iterable), to the end of the current list |
index() | Returns the index of the first element with the specified value |
insert() | Adds an element at the specified position |
pop() | Removes the element at the specified position |
remove() | Removes the item with the specified value |
reverse() | Reverses the order of the list |
sort() | Sorts the list |
Appending Python list
पाइथन हमे append () method उपलब्ध करता है जिसके द्वारा हम लिस्ट के end मे कोई भी एक element को add कर सकते है |
list = ["python",79,"hello",68.78,95,36.2,"program"]
list.append(7895)
print(list)
output :-
['python', 79, 'hello', 68.78, 95, 36.2, 'program', 7895]