In Python, Placeholder is a word, characters or a string of characters to hold a temporary place.
The placeholder behaves as a dynamic place holder in such a way that you can pass a particular value for that placeholder.
Example
Here, you can see that ‘%s‘ is the string placeholder which can hold a string in this place.
The placeholder will be replaced by the value of another variable or the static value itself.
This will be clear from the next example.
Example
Here, you can see that ‘%s‘ will hold a place(value) from %tutorial and the value of tutorial is “TutorialBrain”
Hence, print(ph%tutorial) displays –
TutorialBrain is the best Python Learning Website.
NoteTo use a Numeric placeholder, you have to use %d in place of %s.
Consider the example below -
Example
Directly Passing a value
You can directly pass a value instead of a variable. For %s, you can pass a string but if you use %d, you have to pass a Numeric value.
Example
Note In layout terms, %s will be substituted by a value which is passed the variable that contains %s. In this case, the string value "TutorialBrain" will be be passed to %s of the variable 'ph' because we are using ph%"TutorialBrain"
Python Multiple Placeholder Declaration
You can code any number of placeholders.
If you code 2 placeholders, you have 2 pass 2 values via the argument as below –
Python Multiple Placeholder Declaration
You can code any number of placeholders.
If you code 2 placeholders, you have 2 pass 2 values via the argument as below –