Python / Q&A · May 9, 2021 0

Python print() (Pt. 2)

The “%s” sign

Try this code:

print('%s' % 'Hi!'+' My name is Bob')

Did it print what you thought it would? This is like the substitution method in linear equations. For all the “%s” signs, at the end, after the “%” sign, Using what is after it, replaces the “%s” sign.

Can I use multiple “%s” signs?

Yes! It will be like this:

print('%s' % ('Hi! ', 'My name is Bob'))

Using Braces

print(f'{"Hi! My name is Bob"}')

It is supposed to return the exact same thing.

How does that work?

The “f” sign before the quotes mean that there will be the braces (“{}”) in the quotes. It will print whatever is inside the braces. This will be useful when using variables.