5 ms·
I would add f-strings to the list and some of the string methods especially .strip(), .split(), and .join()
by tony-allan 5y ago
I would add f-strings to the list and some of the string methods especially .strip(), .split(), and .join()
- mkaic 5y agof-strings are so incredibly handy!
- sixstringtheory 5y agoFavorite thing I learned recently was that instead of doing print (f’some_var: {some_var}’) one can just do print (f’{some_var=}’) What’s the next cool thing I should know about f-strings?
- tony-allan 5y agoI hadn't come across f'{some_var=}' before. Output looks like: some_var='abcd' Great find!
- evgenyp 5y agoIt's even more useful for complex expressions e.g. f'{f(x, y)=}' -> 'f(x, y)=5'
- blt 5y agoIn case anyone is wondering how they missed this: The feature was added in Python 3.8, so it wasn't part of the original f-strings feature set. https://docs.python.org/3/whatsnew/3.8.html#f-strings-support-for-self-documenting-expressions-and-debugging https://docs.python.org/3/whatsnew/3.8.html#f-strings-suppor...
- jpm48 5y agoWow, didn't know this one (just added to my lecture notes!) thanks
- deleted 5y ago[deleted]
- minimaxir 5y agoThe reason f-strings are not as popular is because they were added in 3.6 and no one could use them for backward compatibility reasons. Now that 3.7 is the minimum supported version, it's safe to use.
- xapata 5y agoF-strings are the reason I upgraded all my projects.
- ehsankia 5y agowe also FINALLY got removeprefix() and removesuffix()! no more strange `string[:len(suffix)]`
- oneoff786 5y agoFor me, Specifically f”{x:,}” to return the value of x as a comma separated number string
- camel_Snake 5y agofwiw `format(x, ',')` will do this too and looks a bit more readable imo
- oneoff786 5y agoI think that holds true for just x, but not for, say, f”Total Cost: {round(x / 1000000, 1):,}M”