Why does my for() function turns my list into integers? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why does my for() function turns my list into integers?

hello = [1,2,3,4] for hi in hello: print(hi) Output: 1 2 3 4

6th Jan 2021, 3:35 PM
slawbear
slawbear - avatar
3 Answers
+ 1
Interesting question hello here is a variable storing an integer array of 1, 2, 3, 4; if you're expecting your output to be: h e l l 0 then consider this for hi in "hello": print(hi)
6th Jan 2021, 3:43 PM
Fabala Dibbasey
Fabala Dibbasey - avatar
0
@Fabala Dibbasey i want the output to be [1,2,3,4] same as the variable hello
6th Jan 2021, 3:46 PM
slawbear
slawbear - avatar
0
print(hello) Will do it
6th Jan 2021, 3:49 PM
Fabala Dibbasey
Fabala Dibbasey - avatar