+ 1

Nested List

a = ['a', 'b'] n = [1, 2] x = [a, n] print(x[1]) Output [1, 2] Why the output is [1, 2]?

16th Jan 2023, 12:46 AM
Nick
6 ответов
+ 8
x = [a,b],[1,2] 0 1 So, x[1] = [1,2]
16th Jan 2023, 12:54 AM
Ausgrindtube
Ausgrindtube - avatar
+ 7
Ausgrindtube, > the content of x is => [['a', 'b'], [1, 2]]
16th Jan 2023, 2:57 PM
Lothar
Lothar - avatar
+ 5
Happy to help!
16th Jan 2023, 12:59 AM
Ausgrindtube
Ausgrindtube - avatar
+ 4
Completely correct Lothar . Thanks
16th Jan 2023, 3:52 PM
Ausgrindtube
Ausgrindtube - avatar
+ 3
Ooooh. Got it. Thank you so much👌
16th Jan 2023, 12:56 AM
Nick
+ 1
Hola the answer is [1, 2] because of the index you've placed inside x. Please remember that List are ordered and changeable. print(x[1]) Outputs: [1, 2] print(x[0]) Outputs: ['a', 'b'] print(x) Outputs: [['a', 'b'], [1, 2]] ref1: https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_lists.asp
17th Jan 2023, 2:54 PM
Afonso Pena
Afonso Pena - avatar