Ana sayfa
/
Teknoloji
/
What is the result of the following code? my_(-)list=[1,2,3] my list.extend([4, 5]) print(my_list) Error [1,2,3,4,5] [1,2,3,[4,5]] [1,2,3,4]

Soru

What is the result of the following code?
my_(-)list=[1,2,3]
my list.extend([4, 5])
print(my_list)
Error
[1,2,3,4,5]
[1,2,3,[4,5]]
[1,2,3,4]

What is the result of the following code? my_(-)list=[1,2,3] my list.extend([4, 5]) print(my_list) Error [1,2,3,4,5] [1,2,3,[4,5]] [1,2,3,4]

Çözüm

4.3248 Voting
avatar
Hacer
Usta · 5 yıl öğretmeni
Uzman doğrulaması

Cevap

The correct answer is: $[1,2,3,4,5]$<br /><br />Explanation: The code first creates a list named $my_{-}list$ with elements $[1,2,3]$. Then, it uses the extend method to add the elements $[4,5]$ to the end of the list. The extend method adds elements to the end of the list, so the final result is $[1,2,3,4,5]$.
Derecelendirmek için tıklayın: