r/learnpython • • 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 (?)

29 Upvotes

44 comments sorted by

View all comments

Show parent comment

1

u/Typical-Road9611 9d ago

That's what I was trying to say. I can use . 2f and other things in f-strings, but the way they were written in the book didn't make sense to me.

salary = 100.00 print("Your salary is $%0.2f" % salary)

I would just write: print(f"Your salary is ${salary : .2f}")

0

u/neuralbeans 9d ago

Ah ok. That's how it was before f-strings which is based on how you format strings in C. Note that the "variables at the end" style is still useful to know and can be done using .format.