SoFunction
Updated on 2024-10-30

Example of % and f printing variables in python

As shown below:

# Method 1: %
a = "hello"
b = "world!"
print("Hello, %s %s." % (a,b))
# Method II: f
a = "hello"
b = "world!"
print(f"How are you?,{a} {b})

As you can see above, the f method is a bit more concise in terms of code size, but it only supports python 3.6 and later.

"\n" line break

"\t" tab indent

print("After printing, the default is line feed, do not want to line feed with end", end=" ") Output content followed by a space, not line feed.

The above example of % and f of printing variables within python is all that I have shared with you.