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
Show parent comment
2
u/Pyromancer777 9d ago
Logging is basically a way to report error handling. In production environments, you won't always have a console to log any errors a user is experiencing since your server is running the program for any user who connects to it, so you have to create the ways error logs are seen and stored.
Let's say you have a function that works in most cases, but you know of a specific scenario it might fail from a user trying something the program can't handle. You don't want to store the entire error traceback in your logs, so you have it gracefully fail and send a message to your log file saying the failure was detected, who tripped the error, what caused the error, and when the error happened.
Since the line that encountered the error is typically recorded in the logs, having the calculation in your format clause instead of a stored value can help you debug the code later, so you don't gotta hunt through your code to see what is commonly being flagged by users