Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python string formatting: reference one argument multiple times

If I have a string like:

"{0} {1} {1}" % ("foo", "bar") 

and I want:

"foo bar bar" 

What do the replacement tokens have to be? (I know that my example above is incorrect; I'm just trying to express my goal.)

like image 944
Nick Heiner Avatar asked Jan 17 '11 01:01

Nick Heiner


People also ask

What does {: 3f mean in Python?

"f" stands for floating point. The integer (here 3) represents the number of decimals after the point. "%. 3f" will print a real number with 3 figures after the point. – Kefeng91.


1 Answers

"{0} {1} {1}".format("foo", "bar") 
like image 162
mouad Avatar answered Sep 29 '22 08:09

mouad