Computer Science
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( )
Python List Manipulation
28 Likes
Answer
- L1.upper( ) will cause an error as upper() method can be called with Strings not Lists.
- L2.upper( ) will cause an error as upper() method can be called with Strings not Lists.
- L2[1].upper( ) will cause an error as L2[1] is a list — [ "is", "another"] and upper() method cannot be called on Lists.
Answered By
13 Likes
Related Questions
What is the difference between sort( ) and sorted( )?
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 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( )
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]?