DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 970,177 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Mohammed Subhan Khan
Mohammed Subhan Khan

Posted on • Originally published at mskhan.in on

Python f strings

Python f strings allow for string interpolation similar to Swift or JavaScript. They are a new feature introduced in Python 3.6. Let’s look at an example

hello = 'hello'
world='world'
print(hello + ' ' + world)

You can do a similar thing using f strings as follows

hello = 'hello'
world='world'
print(f'{hello} {world}')

String interpolation allows to embed variables into the string. This is especially useful because it does away with casting data types into strings to embed in a string. f strings even allow to embed expressions in {}

x=5
print(f'I have {x+1} apples!')

Usage : f followed by single or double quotes.

Top comments (0)

Update Your DEV Experience Level:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›