报错
报错发生在list -> str的过程中,
使用orderFood接收了用户输入的int值,
orderFood = list(map(int, input().split(',')))
orderFoodStr = ''.join(orderFood)
print(orderFoodStr)
错报是因为join函数的对象应该是str而不能是int,需要借助map()函数将list内每个元素转为str型,再join().
orderFood = list(map(int, input().split(',')))
orderFoodStr = ','.join(map(str,orderFood))
print(orderFoodStr)
python - list/str 互转
list -> str
list1 = ['1','2','3']
str1 = ''.join(list1)
print(str1)list2 = [1,2,3]
str2 = ''.join(map(str,list2))
print(str2)
str->list
str = "12345"
li = list(str)
print(li)li2 = list(map(int,str))
print(li2)