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

How to store multiple lines separated by enter value in a single variable in python? Example is in the description

555
554
33
2444
4555
2455
24555
2555
2335
5555
23455
2455
2344

I want to store all these values in the single variable num, how can I do that?

>Solution :

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

If you are working with a multiple line string you can use split given "\n" as the splitor:

myString = """
555
554
33
2444
4555
2455
24555
2555
2335
5555
23455
2455
2344
"""
myString.strip().split("\n")

Output

['555',
 '554',
 '33',
 '2444',
 '4555',
 '2455',
 '24555',
 '2555',
 '2335',
 '5555',
 '23455',
 '2455',
 '2344']

Note that if you are working with file, you can still use the same approach, but you need to read the file first.

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