functions | Sololearn: Learn to code for FREE!

+5

functions

numbers=[1,2,3,4] numbers.append([5,6,7,8]) print(len(numbers)) How does the output 5 arrives?

4/24/2020 5:06:09 PM

PRIYANKA K

6 Answers

New Answer

+26

If you append [5,6,7,8] to a list that contains [1,2,3,4], the result is like this: [1,2,3,4,[5,6,7,8]]. So there are 5 elements in this nested list: 1 - 1 2 - 2 3 - 3 4 - 4 5 - [5,6,7,8] If you would have used extend() instead of append, the result would be: [1,2,3,4,5,6,7,8].

+3

Thank you so much

0

The print statement return 5 because we have 5 elements in the list

0

Hi there, If you can interested to learn functional testing, you can check https://artoftesting.com/functional-testing

0

The output is 5 because when u append the list[5,6,7,8] will get append into numbers as[1,2,3,4,[5,6,7,8]]

0

you added it to the list