Python Forum
print function help percentage and slash (multiple variables)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print function help percentage and slash (multiple variables)
#1
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.

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)))
Reply


Messages In This Thread
print function help percentage and slash (multiple variables) - by leodavinci1990 - Aug-09-2020, 10:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  print doesnt work in a function ony 2 290 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  How to print variables in function? samuelbachorik 3 902 Dec-31-2022, 11:12 PM
Last Post: stevendaprano
  How to print the output of a defined function bshoushtarian 4 1,279 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  change backslash into slash in a path paul18fr 7 2,336 Jul-21-2022, 04:26 PM
Last Post: deanhystad
  User-defined function to reset variables? Mark17 3 1,644 May-25-2022, 07:22 PM
Last Post: Gribouillis
Sad Iterate randint() multiple times when calling a function Jake123 2 2,039 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  Storing variables into one file for use in multiple Jupyter notebooks devansing 1 1,731 Feb-05-2022, 10:04 AM
Last Post: ibreeden
  Why does absence of print command outputs quotes in function? Mark17 2 1,376 Jan-04-2022, 07:08 PM
Last Post: ndc85430
  return vs. print in nested function example Mark17 4 1,738 Jan-04-2022, 06:02 PM
Last Post: jefsummers
  How can I assign "multiple variables" to a single "value"? Psycpus 2 1,852 Oct-04-2021, 03:29 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020