I have this string: my_str='a pi{ece} of t{ext}'
and these args: args=['ece', 'ext']
When calling: >>> my_str.format(*args)
It gives me: KeyError 'ece'
Any help?
I have this string: my_str='a pi{ece} of t{ext}'
and these args: args=['ece', 'ext']
When calling: >>> my_str.format(*args)
It gives me: KeyError 'ece'
Any help?
I think what you're looking for is fstring. Fstring was added to python 3.6.
hello = "Hello"
person = "Jimmy"
args = [hello, person]
greeting = f"{args[0]}, {args[1]}"
print(greeting)
If you really want to use .format()
hello = "Hello"
person = "Jimmy"
args = [hello, person]
greeting = "{}, {}".format(*args)
print(greeting)
or
hello = "Hello"
person = "Jimmy"
args = [hello, person]
greeting = "{first}, {second}".format(first=args[0], second=args[1])
print(greeting)
Please google fstring and .format()
Fstring is generally faster