In this post we will learn about the string formatting is python, this post is inspired from the realpython. Lets get started,
We will be splitting this String formatting into 4 parts,
“Old Style” String Formatting (% Operator)
“New Style” String Formatting (str.format)
String Interpolation / f-Strings (Python 3.6+)
Template Strings (Standard Library)
“Old Style” String Formatting (% Operator)
We will start with old and simple style used by many, this is most conman with the users who are familiar with low level language. Below we will declare two variable and try to achieve a string output of "The cost of Alienware Area-51m is 2,99,590 rupees"
price = 2,99,590
name = "Alienware Area-51m"
“New Style” String Formatting (str.format)
String Interpolation / f-Strings (Python 3.6+)
Template Strings (Standard Library)