Records#
- Today I learned about the knowledge points of print. By default, print will print a newline character at the end.
- Use end=" " to customize what print will print at the end. For example, end="," will print a comma instead of a newline at the end.
- In the console, \n is a newline, \t is a tab, \v is a vertical tab.
- Use sep=" " to customize the separator for print output, for example, sep="," will use a comma to separate the printed content.
print('\033[?25l', end="")
This statement can turn off the cursor prompt in the console.print('\033[?25h', end="")
This statement can turn on the cursor prompt in the console.- Today's exercise is to write a function that takes two parameters to control the color of the printed output. Indeed, changing the color is permanent. If you want to change it back, you need to print it again, haha!
CODE#
def color(s, t):
if s == "pink":
print("\033[35m", t, sep="", end="")
elif s == "red":
print("\033[31m", t, sep="", end="")
elif s == "green":
print("\033[32m", t, sep="", end="")
else:
print("\033[0m", t, sep="", end="")
print("Super Subroutine")
print("With my ", end="")
color("pink", "new program")
color("red"," I can just call red('and ' ) ")
color("red", "and"),
color("red"," that word will appear in the color I set it to .")
color("red","With no ")
color("green", "weird gaps ")
color("red",".")
color("red","Epic")