+ 2
Why these codes are different outputs?
print([i for i in range(0,3)]*'0') output=TypeError print(len([i for i in range(0,3)]*'0') output=000 why output are different,can anyone explain me.
3 Answers
+ 2
you cannot multiply a list with string.
+ 1
You can only use print("string"*int) to print repeats of a string. The first line is print("string"*list), which is why you get the type error. Are you wanting to print a list of increasing repeats of a string? That sounds fun.
for i in range(3):
print(i*'0')
+ 1
I think you missing a ) in the second code sample...
print(len([i for i in range(0,3)])*'0')