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 can I stored all printed output in a variable

How can I store my output in a variable? Instead of print?

specially, print(*pre_sort_features, sep = '\n')

I tried to like this but It’s not working.

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

custom_var = *pre_sort_features, sep = '\n'

Here is my details code

list = ['Item 01', 'Item 02', 'Item 03']

append_str = '✓'
pre_sort_features = [append_str + sub for sub in list]
print(*pre_sort_features, sep = '\n')
custom_var = *pre_sort_features, sep = '\n'

>Solution :

You probably want this:

list = ['Item 01', 'Item 02', 'Item 03']

append_str = '✓'
pre_sort_features = [append_str + sub for sub in list]
print(*pre_sort_features, sep = '\n')
custom_var = "\n".join(pre_sort_features)
print(custom_var)

See str.join.

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