How to print next values of list in place of %s
? Code below shows result which I expect to get, but I don't want to write every step manually.
hours=["14","15","18","30"]
print (("%s:%s-%s:%s")%(hours[0],hours[1],hours[2],hours[3]))
Is there method to do something like this:
print (("%s:%s-%s:%s")%hours)
and make it work?
You can use format, and use *
to unpack values in the list as parameters to the format
method:
"{}:{}-{}:{}".format(*hours)
# '14:15-18:30'
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments