0

I understand % as modulus, but i do not understand % as used below. What is its function here:

def foo(first, second, third, *therest): print("First: %s" % first) print("Second: %s" % second) print("Third: %s" % third) print("And all the rest... %s" % list(therest)) --------------- I'm not referring to the "%s" (string), but the "% first" etc. in the code. I can't find any explanation of it in my searches

19th Sep 2017, 12:12 PM
Randy
3 Respuestas
+ 1
here % is not modulo operator :( . it is format. (and you miss commas inside print function.) see also https://pyformat.info
19th Sep 2017, 12:16 PM
yuri
+ 1
Thanks Yuri for your answer. The link is very helpful. This code is copied from an online course, so I cannot speak to any other errors.
19th Sep 2017, 12:32 PM
Randy
+ 1
always copy- paste to Code Playground to make sure it work as expected! (maybe, the second % works as a comma).
19th Sep 2017, 12:47 PM
yuri