In this section, we will be discussing the way we can insert or embed any value in a string.
This will be used for name specific automated emails and other similar applications.
Example :
Here we can assign any name ( in this example we used Mathew and Jacob) to the variable and the same variable will recall using %s. %s is act as a place holder. We can call it as inserting values in any section using %s
>>> customer_name = "Mathew"
>>> message = "Hi %s , you have a mail"
>>> print ( message % customer_name)
Hi Mathew , you have a mail
>>> customer_name = "Jacob"
>>> print ( message % customer_name)
Hi Jacob , you have a mail
>>> customer_name = "Jacob"
>>> message = "Hi %s , you have a mail from %s"
>>> other_name = "Alex"
>>> print (message % (customer_name,other_name))
Hi Jacob , you have a mail from Alex
No comments:
Post a Comment