Skip to main content

correct python syntax for print statmets with variables : print(f"{file_name} and other words in the print to console statment")

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.