Jan-07-2021, 09:10 PM
You are confusing .format with f'. This is your example with corrections,
num1=111 num2=222 num3=333 text1 = "numbers: {0},{1},{2}" print(text1.format(num1,num2,num3))The numbers in "numbers: {0},{1},{2}" are index numbers and tell the formatter which argument to print where. This will print the numbers in the opposite order.
num1=111 num2=222 num3=333 text1 = "numbers: {2},{1},{0}" print(text1.format(num1,num2,num3))
Output:numbers: 333,222,111
The code below uses the newest way to format strings, f-Strings.import random r1 =(random.randrange(0, 3)) r2 =(random.randrange(3, 6)) r3 =(random.randrange(6, 9)) print(f'numbers: {r1},{r2},{r3}')When using f-Strings the brackets contain the thing you want to print instead of an index that is used to get the value from the format() function.