Lesser-known Feature of f-strings in Python
While debugging, one often explicitly prints the name of the variable with its value to enhance code inspection.
Although there's nothing wrong with this approach, it makes your print statements messy and lengthy.
f-strings in Python offer an elegant solution for this.
To print the name of the variable, you can add an equals sign (=) in the curly braces after the variable. This will print the name of the variable along with its value but it is concise and clean.
Thanks for reading Daily Dose of Data Science! Subscribe for free to learn something new and insightful about Python and Data Science every day. Also, get a Free Data Science PDF (250+ pages) with 200+ tips.
I like to explore, experiment and write about data science concepts and tools. You could connect with me on LinkedIn.