In INTRODUCTION TO CLASSES - Constructors, problem 8/14, there is an “f” inside of the print function before the start of the string. How would you know when or why you should put an “f” before the string? thank you if anyone sees this or helps me out.
1 Like
That is one form of string formatting, known as, f-string
. It has to do with printing and templating.
def slope_eq (m, b):
return f"y = {m}x + {b}"
print (slope_eq(2, 6)) # y = 2x + 6
We are using string interpolation to insert variable values or expressions in the output string.
Do a quick search for ‘f-string’ to learn more about this very handy tool.
2 Likes
Thank you so much sir. I think I didn’t understand it because it wasn’t explained in the course but you explained it perfectly. have a great day.
2 Likes