'sprintf like function in python

I have code in R and I want to convert that in python, I would like to know the function like sprintf. I have this query,

query1 = sprintf('''select * from table''',, toString(ids), df1, df2)


Solution 1:[1]

Python has a % operator for this.

string = "A = %d\nB = %s\n" % (100, 1000)
print(string)
#output
A = 100
B = 1000

or fstring

string = f"A = {100}\nB = {1000}\n"
print(string)

or format

string = "A = {}\nB = {}\n".format(100,1000)
print(string)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1