[Tutor] A Multiple Concatenation Problem

Alan Gauld alan.gauld at yahoo.co.uk
Thu Sep 17 14:00:39 EDT 2020


On 17/09/2020 18:54, Mats Wichmann wrote:

>>>> for suf in range(1, 11):
> ...     filename = f"<ligand>{suf}.log"
> ...     print(filename)
> ...
> <ligand>1.log
> <ligand>2.log
> <ligand>3.log
> <ligand>4.log
> <ligand>5.log
> <ligand>6.log
> <ligand>7.log
> <ligand>8.log
> <ligand>9.log
> <ligand>10.log


In case that's not clear, Mats is using the new
format-string notation.
You can use the old style format strings similarly:

fmt = "<ligand>.%d.log"
for suf in range(1,11):
   print(fmt % suf)

Or append to a list or...
rather than print...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list