English

Find the output from the given list slicing and extend code.

Advertisements
Advertisements

Question

Find the output from the following code:

L=[100,200,300,400,500]
L1=L[2:4]
print L1
L2=L[1:5]
print L2
L2. .extend(L1)
print L2
Code Writing
Advertisements

Solution

  • L[2:4] selects elements at index 2 and 3.
  • L[1:5] selects elements from index 1 up to index 4.
  • extend() adds all elements of L1 to L2.

Output:

[300, 400]
[200, 300, 400, 500]
[200, 300, 400, 500, 300, 400]
shaalaa.com
  Is there an error in this question or solution?
Chapter 1: Review of Phython - EXERCISE [Page 26]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 1 Review of Phython
EXERCISE | Q 9. | Page 26
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×