Python 3 String Formatting



Juggle some strings and things

There are multiple ways to format strings in Python 3. Let's have at them.

String.

string = 'some text'

Concatenated string.

string = 'some' + ' ' + 'text'

Format

value = 'text'
string = 'some {}'.format(value)

F-strings

value = 'text'
string = f'some {value}'

Old-school Python 2 formatting

value = 'text'
string = 'some %s' % value

All of the examples result in the same string some text.

Thanks for reading. x

Resources