How to use string interpolation (inserting values of variables in place of placeholders) in Python

1 Answer

0 votes
a = 300
b = True
c = "c++"
d = 3.14
e = "python"

print("%d" % a)
print("%d + 88 = %d" % (a, a + 88))
print("%s and %s" % (c, e))
print("[%d, %s, %s, %s, %f]" % (a, b, c, e, d))
print("PI: %f" % d)




'''
run:

300
300 + 88 = 388
c++ and python
[300, True, c++, python, 3.140000]
PI: 3.140000

'''

 



answered Jan 31, 2022 by avibootz

Related questions

4 answers 305 views
4 answers 263 views
1 answer 123 views
3 answers 324 views
1 answer 191 views
1 answer 179 views
...