Skip to content

Commit 0346ea2

Browse files
authored
Update Insertdeleteupdateonlist.md
1 parent c9106ae commit 0346ea2

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Data_Structure_In_Python/List/Insertdeleteupdateonlist.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ print(color)
3333
#### append a another list :page_with_curl:
3434
Example:
3535
```python
36+
#initilize two list
3637
color=['black','red']
3738
color2=['brown','green']
3839

@@ -45,7 +46,10 @@ You can not append more than one element at a time using append
4546

4647
This is wrong example:
4748
```python
49+
#initilize list
4850
color=['black','red']
51+
52+
#Try to Append Two element at time
4953
color.append('brown','green')
5054
#Result Error:-append() takes exactly one argument (2 given)
5155
```
@@ -68,6 +72,7 @@ Both position and element are required element
6872

6973
Example:
7074
```python
75+
#initilize list
7176
color=['black','red','brown']
7277

7378
#insert 'green' element at 1 st position
@@ -95,7 +100,9 @@ print(num)
95100

96101
Example:
97102
```python
103+
#initialize num list
98104
num=[1,3,4,7]
105+
99106
#insert 8 element at -10th position
100107
num.insert(-10,8)
101108

@@ -111,8 +118,11 @@ list1.extend(lst2)
111118
```
112119
Example:
113120
```python
121+
#initilize two list
114122
num1=[1,3,4,7]
115-
nun2=[8, 9]
123+
num2=[8, 9]
124+
125+
#add num2 list to num1
116126
num1.extend(num2)
117127
print(num1)
118128

@@ -138,6 +148,7 @@ del list or element position
138148

139149
Example:
140150
```python
151+
#initilize list
141152
number=[1,3,4,7,8, 9]
142153
#Delete 4 from above list
143154
del number[2]
@@ -150,7 +161,10 @@ print(number)
150161

151162
### How to delete list
152163
```python
164+
#initilize list
153165
number=[1,3,4,7,8, 9]
166+
167+
#delete total list
154168
del number
155169

156170
print(number)
@@ -170,6 +184,7 @@ listname.pop(position)
170184
```
171185
Example:
172186
```python
187+
#initilize list
173188
number=[1,3,4,7,8, 9]
174189
#remove 8 element which present 4 or -2 index
175190
del_val=number.pop(4)
@@ -187,7 +202,7 @@ Example
187202
number=[1,3,4,7,8, 9]
188203
number.pop(100)
189204

190-
#Result:error will occured.
205+
#Result:error will occured. pop index out of range
191206
```
192207

193208

@@ -201,6 +216,7 @@ listname.remove(value)
201216
```
202217
Example:
203218
```python
219+
#initilize list
204220
color=['red', 'green', 'blue']
205221

206222
#Remove "green " From list
@@ -216,7 +232,9 @@ print(color)
216232

217233
Example:
218234
```python
235+
#initilize list
219236
color=['red', 'green', 'blue']
237+
220238
#remove "black" From above list
221239
color.remove("black")
222240

@@ -232,6 +250,7 @@ list[index]="new value"
232250
```
233251
Example:
234252
```python
253+
#initilize list
235254
color=["blue","green","red"]
236255

237256
#update blue with *black*
@@ -244,4 +263,3 @@ print(color)
244263
```
245264

246265
- If you provide out of range index while updating value then it will generate out of range index error
247-
In next tutorial I will write some remaining methods on list

0 commit comments

Comments
 (0)