What are placeholder variables? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What are placeholder variables?

Explain what you mean by placeholder variable. An example will be appreciated.

21st Jan 2021, 11:53 AM
Spellled
Spellled - avatar
5 Answers
+ 1
They are used for formatting strings. %s acts a placeholder for a string while %d acts as a placeholder for a number. Their associated values are passed in via a tuple using the % operator. name = 'marcog' number = 42 print '%s %d' % (name, number) will print marcog 42.
21st Jan 2021, 12:55 PM
Abdul Raheem
Abdul Raheem - avatar
+ 2
Placeholder variables are nontranslatable text strings that stand in for a term or phrase that is used multiple times, or represents a term that shouldn't be translated, such as an official product name. ... A placeholder variable is usually delimited by non-letter characters, such as \+ and \- .
21st Jan 2021, 12:13 PM
SHASHWAT MANDALI
+ 1
Intuitively, a placeholder is a pre-formatted container into which content can be placed. By providing pre-set formatting to its content, it places many of the formatting choices in the hands of the template designer while allowing the end-user to concentrate on the actual content.
21st Jan 2021, 12:51 PM
Abdul Raheem
Abdul Raheem - avatar
+ 1
The placeholders can be identified using named indexes {price} , numbered indexes {0} , or even empty placeholders {} .
21st Jan 2021, 1:20 PM
Abdul Raheem
Abdul Raheem - avatar
+ 1
Insert the price inside the placeholder, the price should be in fixed point, two-decimal format: EXAMPLE= txt = "For only {price:.2f} dollars!" print(txt.format(price = 49))
21st Jan 2021, 1:23 PM
Abdul Raheem
Abdul Raheem - avatar