Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I want to change a variable to have no newline similar to what end='' does in print

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 =

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading