Computer Science
Given two lists:
L1 = ["this", 'is', 'a', 'List'], L2 = ["this", ["is", "another"], "List"]
Which of the following expressions will not result in error? Give output of expressions that do not result in error.
- L1 == L2
- L1.upper( )
- L1[3].upper( )
- L2.upper( )
- L2[1].upper( )
- L2[1][1].upper( )
Python List Manipulation
20 Likes
Answer
- L1 == L2 gives output as false because L1 is not equal to L2.
- L1[3].upper( ) gives output as 'LIST' because L1[3] is 'List' and upper() function converts it to uppercase.
- L2[1][1].upper( ) gives output as 'ANOTHER' because L2[1] ["is", "another"] and L2[1][1] is "another". upper() function converts it to uppercase.
Answered By
12 Likes
Related Questions
What is the difference between following two expressions, if lst is given as [1, 3, 5]
(i) lst * 3 and lst *= 3
(ii) lst + 3 and lst += [3]Given two lists:
L1 = ["this", 'is', 'a', 'List'], L2 = ["this", ["is", "another"], "List"]
Which of the following expressions will cause an error and why?
- L1 == L2
- L1.upper( )
- L1[3].upper( )
- L2.upper( )
- L2[1].upper( )
- L2[1][1].upper( )
Given a list L1 = [3, 4.5, 12, 25.7, [2, 1, 0, 5], 88]
- Which list slice will return [12, 25.7, [2, 1, 0, 5]]?
- Which expression will return [2, 1, 0, 5]?
- Which list slice will return [[2, 1, 0, 5]]?
- Which list slice will return [4.5, 25.7, 88]?
Given a list L1 = [3, 4.5, 12, 25.7, [2, 1, 0, 5], 88], which function can change the list to:
- [3, 4.5, 12, 25.7, 88]
- [3, 4.5, 12, 25.7]
- [ [2, 1, 0, 5], 88]