[Solved] Meaning of ‘{}+{}’ [duplicate]


I’ll break it down for you.

You have a string, ‘{}+{}c’.
In Tkinter, when searching for words, you usually find the position of the first letter, and the last letter. To find the position of the last letter of the word, you need to find the length of the word, and add that to the starting position.

For example, say you have the word ‘hello’. For simplicity, we’ll assume to the position of the first letter, ‘h’, is 1.0.

But we need to also know the position of the last letter, ‘o’.
To do this, we get the length of ‘hello’, which is 5 characters, and add it to the start position, which is 1.0.

1.0 + 5 characters (0.5) = 1.5

So, we now know the position of the last letter.
But how do we tell Tkinter this?
Well, we use ‘+xc’, where x is any number, and c means characters.
In the case of ‘hello’, ‘hello’ is 5 characters long, so we would write ‘+5c’

In your example, the code uses format(). Format is a way to easily use variables with strings.
Your code takes start_pos, the position of the first letter, and the length of the word, len(needle), and passes that into format().

This then replaces the first instance of ‘{}’ with start_pos, and the second instance with len(needle).
This is like writing start_pos + '+' + len(needle) + 'c'

solved Meaning of ‘{}+{}’ [duplicate]