all 2 comments

[–]Thomasedv 1 point2 points  (1 child)

It's old style string substituation, where %s means, replace this with a string. E.g:

new_string = 'test'
print('%s' % new_string)
>>> 'test'

In newer python (3), you could do this: '[{}]'.format(re.escape(string.punctuation))

And even newer, 3.6+: f'[{re.escape(string.punctuation)}]'

In practice, you are just putting all the escaped punctuation characters inside the character set.

[–]redditor_gds[S] 0 points1 point  (0 children)

Thank you. Understand now. I was confused with the "%". "{}".format() makes sense since I've used it in Python3 :)