0% found this document useful (0 votes)
24 views7 pages

X (1,2,3,4,5,6) X (1,2,3,4,5,6) First Index:-X (0) 1 End Index: - X (-1) 6 Fromatob X (A:b) Note That The End Number Not Taken

The document discusses various methods for manipulating lists in Python including: - Accessing elements by index (both positive and negative indices) - Slicing lists to extract sublists - Getting the length of a list - Common mutating methods like append, insert, pop - Using range to generate lists of numbers - Sorting lists and reversing their order

Uploaded by

abdullah azayem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views7 pages

X (1,2,3,4,5,6) X (1,2,3,4,5,6) First Index:-X (0) 1 End Index: - X (-1) 6 Fromatob X (A:b) Note That The End Number Not Taken

The document discusses various methods for manipulating lists in Python including: - Accessing elements by index (both positive and negative indices) - Slicing lists to extract sublists - Getting the length of a list - Common mutating methods like append, insert, pop - Using range to generate lists of numbers - Sorting lists and reversing their order

Uploaded by

abdullah azayem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

>>>x=[1,2,3,4,5,6]

>>>x
[1,2,3,4,5,6]
First index:-
x[0]=1
End index:-
X[-1]=6
From a to b
X[a:b]
Note that the end number not taken :-
>>>X[0:5]
[1,2,3,4,5]
From start to end
>>>x[:]
[1,2,3,4,5,6]
>>>x[-2]
5
>>>x[:2]
[1,2]
The length of list :-
>>>len(x)
6
To add number :-
>>>x.append(7)
[1,2,3,4,5,6,7]
To choose the position of the element:-
x.insert(position,element)
>>>x.insert(1,2)
[1,2,2,3,4,5,6,7]
To delete element from the list:-
x.pop(position)
>>>x.pop(1)
[1,2,3,4,5,6,7]
To make list from a to b :-
Using range
>>>range(10)
[0,1,2,3,4,5,6,7,8,9]
Start from zero to the (end number-1)
>>>x[5:]
[5,6,7,8,9]
>>>x[:5]
[0,1,2,3,4]
Using range but youll define the start
and end element
Range(start,end)
>>>range(0,5)
[0,1,2,3,4]
Note that end element Not taken.
Using range but youll define the start
,end and steps of elements:-
-Range(start,end,step)
Note:-if you dont write the step become
(1)
>>>range(0,10,2)
[0, 2, 4, 6, 8]
To change the first and end number :-
>>>y=[1,2,3,4,5]
>>>y[::-1]
[5,4,3,2,1]
To start from smallest to the largest
number:-
>>>y=[100,99,98,97,96,95,94,93]
[100,99,98,97,96,95,94,93]
>>>y.sort()
[93, 94, 95, 96, 97, 98, 99, 100]
To return
>>>y[::-1]
[100,99,98,97,96,95,94,93]

>>> S=Hello World


To separate between the words :-
>>>s.spilt( )
['Hello', 'World']
To know the position of index number :-
>>>s.find(W)
6
>>>s[ : :-1]
'dlroW olleH'

You might also like