Traditional Culture Encyclopedia - Weather inquiry - Why do print (f "* * * *") and Print(“* * * * * ") have different results when printing in python? They're just F.

Why do print (f "* * * *") and Print(“* * * * * ") have different results when printing in python? They're just F.

The difference between printing functions with and without f lies in printing expressions. When printing is an expression, printing with F can execute the expression, and printing without F just outputs the expression as a string. Next, let's use a concrete example to demonstrate:

1, write a function, and print out this function with f parameter, as shown in the figure below.

2. After executing the result, you can see that the expression function in print has been operated, as shown in the following figure.

3. Then remove the f parameter from the print, as shown in the figure below.

4. Next, you can see that the expression function in print is not calculated, and it is directly output as a string, as shown in the following figure.