4 ms·
> I would argue Python is very consistent in its design, it aims to only have one obvious way to do things This argument is dead the second one stumbles upon t
by SSLy 4y ago
> I would argue Python is very consistent in its design, it aims to only have one obvious way to do things
This argument is dead the second one stumbles upon the string interpolation/formatting situation. Or the list comprehensions, ew.
- justin_oaks 4y agoFor the benefit of those not familiar with the Python string interpolation/formatting situation, I present 4 ways to perform the same string formatting: who='World' #1 - string concatenation 'Hello, ' + who + '!' #2 - % operator 'Hello, %s!' % who #3 - format() method 'Hello, {}!'.format(who) #4 - f-strings f'Hello, {who}!'
- jonnytran 4y agoDon't forget all the variations on how to use the format() method. # In order 'Hello, {}!'.format(who) # Numbered 'Hello, {0}!'.format(who) # Named 'Hello, {name}!'.format(name = who)