हिंदी

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

Advertisements
Advertisements

प्रश्न

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
कोड लेखन
Advertisements

उत्तर

  • 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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 1: Review of Phython - EXERCISE [पृष्ठ २६]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
अध्याय 1 Review of Phython
EXERCISE | Q 9. | पृष्ठ २६
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×