Home > Mobile >  How can I stored all printed output in a variable
How can I stored all printed output in a variable

Time:01-12

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.

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'

CodePudding user response:

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.

  •  Tags:  
  • Related