Skip to content

String interpolation in Python

Since Python 3.6, there is a way to interpolate strings, by using so called f-strings. To use them, simply add a f before the starting quotation mark of the string and add the variable names you want to use enclosed by curly brackets ({ and }):

name = "John Doe"
message = f"Hello, {name}!")
# value of message: "Hello, John Doe!"

(source)

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.