4 ms·
Favorite 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 c
by sixstringtheory 5y ago
Favorite 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