FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
programminginpython.com/listOperations.py at master · avinashn/programminginpython.com · GitHub
avinashn
/
programminginpython.com
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
53
Star
68
Code
Issues
0
Pull requests
3
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
programminginpython.com
/
listOperations.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (25 loc) · 1.03 KB
Breadcrumbs
programminginpython.com
/
listOperations.py
Copy path
File metadata and controls
35 lines (25 loc) · 1.03 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
__author__
=
'Avinash'
lst
=
[
'abc'
,
'def'
,
'ghi'
,
'jklm'
,
'nopqr'
,
'st'
,
'uv'
,
'wxyz'
,
'23'
,
's98'
,
'123'
,
'87'
]
# prints the length of the list
print
(
'Length of the list is : '
,
len
(
lst
))
# appends an item to the list
lst
.
append
(
'sdd'
)
print
(
'
\n
The list appended a new element "sdd" at the end
\n
'
,
lst
)
# changes the value of an item in a list
lst
[
0
]
=
'aaa'
print
(
'
\n
The value of the first element in the list is changed to "aaa"
\n
'
,
lst
)
# Slicing
# shows only items starting from 0 upto 3
print
(
'
\n
List showing only items starting from 0 upto 3
\n
'
,
lst
[:
3
])
# shows only items starting from 4 to the end
print
(
'
\n
List showing only items starting from 4 to the end
\n
'
,
lst
[
4
:])
# shows only items starting from 2 upto 6
print
(
'
\n
List showing only items starting from 2 upto 6
\n
'
,
lst
[
2
:
6
])
# reverse all items in the list
print
(
'
\n
List items reversed
\n
'
,
lst
[::
-
1
])
# removing items from list
lst
[:
1
]
=
[]
print
(
'
\n
First element is removed from the list
\n
'
,
lst
)
# removing whole list
lst
[:]
=
[]
print
(
'
\n
Complete list removed
\n
'
,
lst
)
Back
|
FazBrowse Home
|
New Git URL