+ 11
functions
numbers=[1,2,3,4] numbers.append([5,6,7,8]) print(len(numbers)) How does the output 5 arrives?
11 Antworten
+ 47
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].
+ 5
Thank you so much
+ 3
The print statement return 5 because we have 5 elements in the first list and this contains another list at fifth position
+ 1
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
0
5 because the append is a list contains numbers
0
just beginning here. append(5) works for adding a single value, but for a list we need extend. it's like joining a new list to exisiting one.
0
Append will directly assumes it's parameter as single element
before : [1, 2, 3, 4]
after : [1, 2, 3, 4, [5, 6, 7, 8]]
0
Yes
0
Well, the number 5 is added in fifth position.