Format string in Python
in post we will find how to format string with simple f function instead of writing complex messy statement.
for example if we want to add input variable with static string in python.
we have complex option like below.
name = input(" enter your name : ")
age = input(" enter your age : ")
outputString = (name +" is " + age +" years old")
print (outputString)
instead of formating string with + and " we can using simple function f to format string as below.
name = input(" enter your name : ")
age = input(" enter your age : ")
outputString = f'{name} is {age} years old'
print (outputString)
Comments
Post a Comment