def make_pizza(*toppings):
for j in range(0,len(toppings)):
print(str(j) + toppings[j])
list1 = ['s1','s2','s3','s4']
list2 = ['s3','s45','s4','s5']
make_pizza(list1,list2)
make_pizza('sdf','asdf','asdf','asdf')
运行结果出现错误如下:
r@r:~/python$ python3 1.py
Traceback (most recent call last):
File "1.py", line 6, in <module>
make_pizza(list1,list2)
File "1.py", line 3, in make_pizza
print(str(j) + toppings[j])
TypeError: must be str, not list
The key is that in the print() brackets, the type connected by the plus sign must be str. Solid must convert the list to str
There must be a non-str type object where str is needed.
Solution: forced conversion to str