add colour to text in python

def colored(r, g, b, text):
    return "\033[38;2;{};{};{}m{} \033[38;2;255;255;255m".format(r, g, b, text)
text = 'Hello, World'
colored_text = colored(255, 0, 0, text)


print(colored(255, 0, 0, 'Hello, World'))

Here is what the above code is Doing:
1. The colored function takes in three parameters: red, green, and blue.
2. The function returns a string that begins with the escape sequence \033[38;2;.
3. The escape sequence sets the color of the text that follows.
4. The escape sequence ends with the letter m.
5. The string that was passed into the function is concatenated with the escape sequence.
6. The escape sequence \033[38;2;255;255;255m is concatenated to the end of the string. This escape sequence sets the color of the text back to white.
7. The resulting string is printed to the console.