Python strings

I started out with “+”, then was told not to use it. So I listened and used “join”. Then later I used format. Now it seems that I should use “f”.

f'{s} {t}'               # 78.2 ns
s + '  ' + t             # 104 ns
' '.join((s, t))         # 135 ns
'%s %s' % (s, t)         # 188 ns
'{} {}'.format(s, t)     # 283 ns
Template('$s $t').substitute(s=s, t=t)  # 898 ns

ref:
https://martinheinz.dev/blog/13
https://twitter.com/raymondh/status/1205969258800275456

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s