Example Code:
list1 = [1,2,3]
for i in list1:
if i == 123:
print('E')
else:
pass
Here I want to make the variable of i = 123 and not
i =
1
2
3
Basically remove newlines
I know of the end=” used in print statements is there something like that, that can change the variable itself?
>Solution :
If your goal is to concatenate the list, this returns ‘123’ as an integer:
list1 = [1,2,3]
var = [str(i) for i in list1]
new_var = ''.join(var)
num = int(new_var)
print(num)