I'd like to print a message with a list separated by \n inside an f-string in python3.
my_list = ["Item1", "Item2", "Item3"]
print(f"Your list contains the following items:\n\n{my_list}")
Desired output:
# Your list contains the following items:
# Item1
# Item2
# Item3
One possible solution, chr(10) evaluates to newline:
my_list = ["Item1", "Item2", "Item3"]
print(f"Your list contains the following items:\n{chr(10).join(my_list)}")
Prints:
Your list contains the following items:
Item1
Item2
Item3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With