new line with variable in python -


when use "\n" in print function gives me syntax error in following code

from itertools import combinations a=[comb comb in combinations(range(1,96+1),7) if sum(comb) == 42] print (a "\n") 

is there way add new line in each combination?

the print function adds newline you, if want print followed newline, (parens mandatory since python 3):

print(a) 

if goal print elements of a each separated newlines, can either loop explicitly:

for x in a:     print(x) 

or abuse star unpacking single statement, using sep split outputs different lines:

print(*a, sep="\n") 

if want blank line between outputs, not line break, add end="\n\n" first two, or change sep sep="\n\n" final option.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -