0

Python - What's the error in this code?

Why list is not joined? Compiler tells me something as "string expected, int found" def func(x): for i in range(x): yield i**2 print(",".join(list(func(3))))

10th Feb 2020, 8:00 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
2 Réponses
+ 9
It's because you can't join a list of integers. The elements of the list have to be a string. Here is a fix: print(",".join([str(i) for i in func(3)]))
10th Feb 2020, 8:03 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 7
or yield str(i**2)
10th Feb 2020, 8:15 PM
Oma Falk
Oma Falk - avatar