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?

  1. L1 == L2
  2. L1.upper( )
  3. L1[3].upper( )
  4. L2.upper( )
  5. L2[1].upper( )
  6. 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