Entries published on January 20, 2020
Having some fun with Python
The other day on a Slack I hang out in, someone posted an amusing line of Python code:
port = "{port}:{port}".format(port=port)
If it’s not clear after the inevitable Swedish-chef-muppet impression has run through your mind, this string-formatting operation will replace the contents of port
with a string containing two copies of whatever was in port
, separated by a colon. So if port
was "foo"
, now it will be "foo:foo"
.
Someone of course suggested using f-strings for a more readable version:
port = f"{port}:{port}"
But the person working with it replied they …