I'm working on a school assigment for python/pandas and wanted to try out f strings as seemed very handy way of formatting.
After reading documentation, I realised that I couldn't use \n to format the output. For this code:
f"Shape of dataset:\n {df.shape} (rows, columns)\n"
I get this output:
Out[38]: 'Shape of dataset:\n (270792, 11) (rows, columns)\n'
Which is exactly what I expected after reading the docs.
But then, when I surround it by a print()
, as such:
print(f"Shape of dataset:\n {df.shape} (rows, columns)\n")
I get it looking the way I wanted:
Shape of dataset:
(270792, 11) (rows, columns)
I know I could just use regular formatting as well, but I'm curious as to why this is. Is it that the f string component is ignored because of the print
?