Pythons=12sappend56prints2
The output of the above code is:
[5, 6]
Explanation:
- The list
sinitially contains two elements:1and2. - The
append()method is used to add a new element to the end of the lists. - The new element is a list itself,
[5, 6]. - Therefore, the final list
scontains three elements:1,2, and[5, 6]. - When we print
s[2], we are accessing the third element of the lists, which is[5, 6]. - Therefore, the output is
[5, 6].
原文地址: https://www.cveoy.top/t/topic/hdIU 著作权归作者所有。请勿转载和采集!