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

What are placeholder variables?

9th Dec 2016, 11:33 AM
Anusuya V
Anusuya V - avatar
9 Answers
+ 16
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. Note that name is a string (%s) and number is an integer (%d for decimal).
9th Dec 2016, 11:34 AM
Vipul Walia
Vipul Walia - avatar
+ 13
with reference to Python, why spam and eggs and foo and bar
9th Dec 2016, 11:38 AM
Anusuya V
Anusuya V - avatar
+ 3
thank you so much
9th Dec 2016, 11:36 AM
Anusuya V
Anusuya V - avatar
+ 3
The word you're look is metasyntactic variable It is a placeholder name used in computer science, a word without meaning intended to be substituted by some objects pertaining to the context where it is used. The word foo as used in IETF Requests for Comments is a good example.
9th Dec 2016, 11:44 AM
Vipul Walia
Vipul Walia - avatar
+ 1
You're most welcome
9th Dec 2016, 11:37 AM
Vipul Walia
Vipul Walia - avatar
+ 1
The best way is using . format: Print(" my name is {}".format("john")) You can use it in python 3 or above. Goole .formt in python for more info
9th Dec 2016, 5:53 PM
alisanie
alisanie - avatar
+ 1
But it takes a longer time. Are there other examples you can cite cuz i think using the normal print (name, number) would have saved a lot of time. I'm new here so I'm trying to learn. Anyone?
24th Aug 2019, 4:10 PM
Onimisi
Onimisi - avatar
+ 1
In python 3, you should always use print(f"there are many variables{x} here")
4th Feb 2020, 1:19 PM
Abhijit Paul
Abhijit Paul - avatar
0
Print("my name is {}. Format ("vij"))
24th Mar 2021, 2:12 AM
G Vijay
G Vijay - avatar