0

I use this answer for printing colored in python, but for printing variable I have problem because it prints it like a tuple like below:

from termcolor import colored
val = 'fruit'
print(colored(('Banana is', val), 'yellow'))
>>> ('Banana is', 'fruit')

But this is the output I want:

>>> Banana is fruit

(also without apostrophe)

Niko Föhr
  • 28,336
  • 10
  • 93
  • 96
Meysam
  • 409
  • 4
  • 14

2 Answers2

2
print(colored(f"Banana is {val}", 'yellow'))
Tom Ron
  • 5,906
  • 3
  • 22
  • 38
1

The f behind the string makes it so u can insert variables into a string

print(colored(f"Banana is {val}", 'yellow'))