Weird percent sign in source code

I can’t understand the meaning of ‘%’ in the source code below. Questions have been recorded in the comments.

class RedirectView(View):
    """Provide a redirect on any GET request."""
    permanent = False
    url = None
    pattern_name = None
    query_string = False

    def get_redirect_url(self, *args, **kwargs):
        Return the URL redirect to. Keyword arguments from the URL pattern
        match generating the redirect request are provided as kwargs to this
        if self.url:
            url = self.url % kwargs # 1. what's the meaning of '%' here? a literal and a dict.
        elif self.pattern_name:
            url = reverse(self.pattern_name, args=args, kwargs=kwargs)
            return None

        args = self.request.META.get('QUERY_STRING', '')
        if args and self.query_string:
            url = "%s?%s" % (url, args) # 2. And here, a literal string and a tuple
        return url

OMG! A sting format operation.

1 Like