facebook pixel
I was writing this: “Hello “ + name + “, you are “ + str(age) + “ years old.” Then I found out Python had a cleaner way. I’ll never go back. It’s called an f-string. Put an f before the quote. Write your variable inside curly braces. f”Hello {name}, you are {age} years old.” Read it like a sentence. That’s the whole thing. 3 things that make f-strings genuinely powerful: → Expressions: f”Sum: {5 + 3}” → Sum: 8 → Rounding: f”Pi: {3.14159:.2f}” → Pi: 3.14 → ML output: f”Accuracy: {acc:.1%}” → Accuracy: 94.3% That last one — compare this: “Accuracy: “ + str(round(acc*100,1)) + “%” With this: f”Accuracy: {acc:.1%}” Same output. One is readable. One rule: the f goes BEFORE the quote. That’s genuinely all there is to learn. Day 9 of learning Python for data science — documenting everything so you have a shortcut I didn’t. Were you using string concatenation before f-strings? Drop it below. #Python #Fstrings #PythonTips #LearnPython #DataScience PythonForBeginners aartii_py Machine...

 3.9k

 30

 3.9k

    Suggested Credits
    Tags, Events, and Projects