Can we provide any input type to the format() method?


#1

Question

In the context of this exercise, can we provide any input type to the format() method?

Answer

Yes, you can provide almost any type of input to the format() method, including strings, numerical values, booleans, and objects. You can also provide expressions, like 1 + 4, which will be evaluated and then formatted into the string.

Example

a = 10
b = 20

print("{} + {} = {}".format(a, b, a+b))
# 10 + 20 = 30

print("{}".format(a < b))
# True