In this simple python example:
arr = [1,2,3,4,5]
for n in arr:
s = str(n)
print(s)
What I want to write is a code somehow similar to [str(n) for n in arr] but in the following format:
arr = [1,2,3,4,5]
for str(n) as s in arr:
print(s)
I basically want to include s=str(s) inside for statement. Is the any handy way to do so in python?
for n in arr: print(n)no need to pass tostrprint(n)directly. The second example with the list comprehension is also just fine. The third example doesn’t make sense, though.s = str(s), and still wantsto be astrregardless of its initial type?