You are still mixing up the .format with f-String.
If you use .format() then the thing in brackets {0} is an index that says which argument to use in the format string.
print("{0} {1} {2}".format('a', 'b', 'c')
^ ^ ^ | | |
| | | | | |
----|---|------------ | |
----|----------------- |
-----------------------
Output:
a b c
You can leave the index values out and they are assumed to be 0, 1, … going from left to right.
[python]print("{} {} {}".format('a', 'b', 'c')
Output:
a b c
When using format you cannot put anything in the brackets except
an integer which will be used as an index. You cannot use a variable that contains the index number. Python does not evaluate the things in the brackets when using .format. That only happens with f-Strings
To do what you want I would change the order of the items and leave the format string alone.
# random color
import random
colors = (111, 222, 333)
new_color = random.choices(colors, k=3)
text1 = "new Color is: {0},{1},{2}"
print(text1.format(*new_color))
You can also change the format string, but I think this is really messy and advise against it.
# random color
import random
positions = ('{0}', '{1}', '{2}')
random_positions = random.choices(positions, k=3)
random_format = "new Color is: {},{},{}".format(*random_positions)
print(random_format) # <- So we can see the format string
print(random_format.format(111, 222, 333)) # <- Using the format string
Output:
new Color is: {1},{0},{2}
new Color is: 222,111,333
And if you really want to drive yourself insane you can use .format and f-Strings together like this:
# random color
import random
p0 = random.randint(0,2)
p1 = random.randint(0,2)
p2 = random.randint(0,2)
print(p0, p1, p2)
print(f'new Color is {{{p0}}},{{{p1}}},{{{p2}}}'.format(111, 222, 333))
Output:
0 2 2
new Color is 111,333,333
This is truly horrible, but I think it does what you want and is the solution that is closest to your initial attempt. Those triple brackets are required because double brackets "{{" or "}}" is how you treat a bracket as a normal character.