Informatics Practices
What will be the output of the following statement?
list1 = [12, 32, 65, 26, 80, 10]
sorted(list1)
print(list1)
Python List Manipulation
6 Likes
Answer
[12, 32, 65, 26, 80, 10]
Working
In the given code, list1 is initialized as [12, 32, 65, 26, 80, 10]. The sorted(list1) function is called, which creates and returns a new list with the elements of list1 sorted in ascending order, but it does not modify the original list1. Since the sorted result is not stored or printed, the next line print(list1) outputs the original unsorted list [12, 32, 65, 26, 80, 10].
Answered By
4 Likes
Related Questions
Find the output of the following:
L1=[1, 2, 3] L2=[4, 5, 6] print(L1+list ("45") ) print(L1.pop()) L1.remove (2) print(L1) L1.extend (L2) print(L2)What will be the output of the following statement?
list1 = [12, 32, 65, 26, 80, 10] list1.sort() print(list1)What will be the output of the following statement?
list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] list1[::-2] list1[:3] + list1[3:]What will be the output of the following statement?
list1 = [1, 2, 3, 4, 5] list1[len(list1)-1]