why the output put is [1,2,,3,"40,5"] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
3rd Jan 2020, 7:48 PM
Yusof
Yusof - avatar
4 Answers
+ 6
Initially, num=[1,2,3] num.append("4") # by now num = [1,2,3,"4"] num[3]+=str(.5) # .5 is actually 0.5 (a float) # str(0.5) => "0.5" # num[3] is "4", concatenate that # with "0.5" and it becomes "40.5" # by now num = [1,2,3,"40.5"] That's what happened, and how : )
3rd Jan 2020, 7:59 PM
Ipang
+ 5
Yusof , it's normal when you concatenate two strings =>"4" +"0.5" = "40.5" 🐱
3rd Jan 2020, 7:52 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
3rd Jan 2020, 8:30 PM
Yusof
Yusof - avatar
+ 2
Ipang Thanks
3rd Jan 2020, 8:30 PM
Yusof
Yusof - avatar