DEV Community

Discussion on: Python3 Programming - Exercise 7 - String operations and function

Collapse
 
nitinkatkam profile image
Nitin Reddy

Although string concatenation is great for when you have few variables and short string literals, Python has string interpolation to join string variables with string literals. Look at this:

first_name = "Nitin"
last_name = "Reddy"
full_name = f"{first_name} {last_name}"
print(full_name)
Enter fullscreen mode Exit fullscreen mode

It saves time and reduces complexity when have a more complex string like this:

msg = f"Dear {full_name}, Please note that your payment of {amount} is due on {due_date}. -The Electric Company"
print(msg)
Enter fullscreen mode Exit fullscreen mode