Aug-09-2020, 10:36 PM
(This post was last modified: Aug-09-2020, 10:36 PM by leodavinci1990.)
What is the function of adding a back slash in the following code after the percentage operator? I am testing it without the slash and it gives the same result.
Please note that I know I am not currently using the best practice for string formatting (format function method) in this example.
Please note that I know I am not currently using the best practice for string formatting (format function method) in this example.
def distance(a,b): """ a and b are tuples. Finds the distance between them """ return ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5 p1=(10,10) p2=(10,20) p3=(20,20) print("The distance between %s and %s is %0.1f."%\ (str(p1),str(p2),distance(p1,p2))) print("The distance between %s and %s is %0.1f."%\ (str(p1),str(p3),distance(p1,p3)))