Skip to main content

correct python syntax: print(f"{file_name}")

print(f"{file_name}")
 is this correct?



This code line alone will not print anything unless you have defined the variable file_name and assigned a value to it.

Assuming file_name is defined and has a value, the code line print(f"{file_name}") is correct syntax for printing the value of the variable file_name using an f-string in Python 3.6 and later versions.

The f-string is a string literal that is prefixed with the letter "f" or "F" and allows you to embed expressions inside curly braces {}. When the string is evaluated, the expressions inside the curly braces are replaced with their values.