0

Empty variable Confusion

#Code: numbers = [1, 2 ,3] for x_count in numbers: output = '' ## My questions in ##this line for count in range(x_count): output += "x" print(output) ##### In that above code, why did we declare an empty variable and how can we know that where we need to declare such type of empty variable. Is there any alternative for this.

27th Jun 2019, 3:28 AM
Samir
Samir - avatar
2 Respuestas
+ 1
It's not an empty variable, it's an empty string. It's declared like this, because if we don't declare it and try adding something to it will cause an error.
27th Jun 2019, 4:47 AM
Airree
Airree - avatar
+ 4
I am pretty sure you will get an output like this: 1 2 3 If so, your code is just: numbers = [1, 2 ,3] for x_count in numbers: print(x_count) x_count is a variable which will be filled in each iteration with a value from list numbers. Or if you want to get this: x xx xxx code is: numbers = [1, 2 ,3] for x_count in numbers: print('x' * x_count)
27th Jun 2019, 5:42 AM
Lothar
Lothar - avatar