fsting in python 1

fsting in python

>>> name = 'Fred'
>>> age = 42
>>> f'He said his name is {name} and he is {age} years old.'
# He said his name is Fred and he is 42 years old.

Here is what the above code is Doing:
1. The f in front of the string indicates that this is a format string.
2. The {name} and {age} are placeholders for the variables in the format string.
3. The .format() method is called on the format string, and the variables are passed in as arguments.
4. The format string is replaced with the variables.

Similar Posts