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
Post a Comment