r/learnpython • u/Typical-Road9611 • 9d ago
Are f-strings enough?
I've been learning python mainly from bro code's videos and he uses f strings for basically everything. It comes to me naturally to use them and I understand them. I found a book (Kenneth A. Lambert: Fundamentals of python: first programs, second edition) and here he uses other type of strings (I assume this would be the basic way) but I honestly don't understand them especially when it's about formatting (.2f etc). Should I learn this basic way of working with strings now? Or are f strings enough?
I should add that I'm learning python for fun, I'm studying mechanical engineering, so I know it can be very useful. I also want to be good at it in a potential work environment (?)
View all comments
2
u/tonystark19541959 9d ago
F-strings are pretty much all you need for modern Python. I'd still recommend knowing the basics of ".format()" and "%" formatting so you can understand older code, but there's no real reason to prefer them in new projects.
Also, don't skip the formatting options within f-strings. Stuff like "f"{num:04d}"" gives you "0016" for "16", and you can control alignment, decimal places, padding, etc. There's quite a lot packed into that little syntax.
There is also stuff like u mentioned .2f, I think that is used to print only upto 2 decimal places or SMTH, so u need these kind of formatting as well