I've used Python for years and didn't know this feature existed.

Check out this code.

Just a simple Python dictionary.

But if you look closer, you will notice something strange

“role” and “content” are key-value pairs.

What the heck is this line doing?

Turns out Python has implicit string concatenation.

If you put strings next to each other in the same expression, like dictionaries, tuples, or lists, Python will automatically concatenate them.

So these two adjacent strings in the same dictionary will be concatenated to produce one string:

"Answer using only the provided context. Cite page numbers. "
"If the answer isn't in the context, say it's not in the document."

# becomes this
"Answer using only the provided context. Cite page numbers. If the answer isn't in the context, say it's not in the document."

I’ve never seen this before, so I looked it up to see when Python added this feature

They have had this since day one.

Will I use this feature though?

I don’t know.

But it can definitely catch people off guard if they don’t know this exists.

- Fee from Anime Coders

Keep Reading