Professional Documents
Culture Documents
Ascending Order Small Value To Greater Value Descending Order Greater Value To Smaller Value
Ascending Order Small Value To Greater Value Descending Order Greater Value To Smaller Value
sort()
sort() is used to sort the list elements. Sorting means arranging either in ascending order
or in descending order. Default order is ascending order. In order to sort in descending
order we need to give value as "reverse=True"
l=[4,9,2,1,7,5]
l.sort() ascending order=small value to
print(l) greater value
l=[4,9,2,1,7,5]
l.sort(reverse=True) step 1:
print(l) [1,2,4,5,7,9]
output: step 2:
[9,7,5,4,2,1] [9,7,5,4,2,1]
names=['grapes','banana','apple','orange']
names.sort()
print(names)
output:
D:\>py program1.py
['apple', 'banana', 'grapes', 'orange']
names=['grapes','banana','apple','orange']
names.sort(reverse=True)
print(names)
output:
['orange','grapes','banana','apple']
name=['ramya','rani','raju']
name.sort()
print(name)
[33,66,77,88,99,100]
Aliasing:
The process of assigning a reference variable for existing list(storing the same list in
another reference variable) is called aliasing
l1=[10,20,30,40]
l2=l1
10 20 30 40
Python 22 batch 7 pm Page 2
l1=[10,20,30,40]
l2=l1
10 20 30 40
print(id(l1))
print(id(l2))
l1
l1=[10,20,30,40] l2
l2=l1
l1[1]=777 [10,777,30,40]
print(l1) a.[10,20,30,40]
print(l2) b.[10,777,30,40]
output:
D:\>py program1.py
[10, 777, 30, 40]
[10, 777, 30, 40]
cloning: