Ask coding questions

← Back to all posts
How can i make this a def function?
Imthebestthe (108)

Hello! Firstly, this code is not mine. It is @bobthetomatopie 's code so thanks for that. Secondly, is there a way to make it so that you can do blue('Text here') and the text in that quotes will be blue. Also, how can you do this is other situations. Thanks so much and I really appreciate all the help that you guys give me!
Thanks to everyone who has answered. Appreciate it

Answered by 19wintersp (1142) [earned 5 cycles]
View Answer
19wintersp (1142)

To make the text a colour, you can print the code, then the text. The easiest way would be to just do:

print(blue + "Hello world!")

However, if you want a function, you could do:

def printBlue(message):
  print(blue + message)

This defines the function printBlue, which does the same as the first code example.



you just have to name your def. Try this.

def example():
  return red + "example"


like that. Just call it at the end, and use return.
That should work

BobTheTomatoPie (3362)

This should do it, but the function is prolly not very usefull when you can just go print(blue + 'hello')

def blue(text):
   print(blue + text)

also ppl have already told you this. I just saw i was pinged so i came over to answer as well