Python logic in assignment

python

Solution

I hate this Python idiom, it's completely opaque until someone explains it. In 2.6 or higher, you'd use:

protocol = "https" if secure else "http"

Problem

Given that `secure` is a boolean, what do the following statements do? Especially the first statement. - `protocol = secure and "https" or "http"` - `newurl = "%s://%s%s" % (protocol,get_host(request),request.get_full_path())`

Original source