DEV Community

Discussion on: 30 Days of Python πŸ‘¨β€πŸ’» - Day 2 - Data Types I

Collapse
 
arindamdawn profile image
Arindam Dawn

After reading some articles and blog posts I found out that:

  • %-format method is a very old method for interpolation and is not recommended to use as it decreases the code readability.
  • In str.format() method we pass the string object to the format() function for string interpolation.
  • In the template method, we make a template by importing template class from built-in string module.
  • Literal String Interpolation method is powerful interpolation method which is easy to use and increase the code readability.

I am still figuring out the best practices but I personally like the f syntax.

And yes learning python is a real joy. Hope I keep getting better at it :) Thanks for reading the blog.

Collapse
 
mowat27 profile image
Adrian Mowat

Yeah me too. f'{}...' usually meets my needs and I only use format when I need to use printf style formatting or the expression I want to print is complex enough to impact readability inside a simple interpolation.

I believe the %-format approach is from python2 and str.format() is preferred in python3. You still see it a lot though.