二手产品经理

二手产品经理

THIS IS RENO

Learn Python Online in 100 Days - Week 5 Day 1

Records#

  1. Today I learned about the knowledge points of print. By default, print will print a newline character at the end.
    Catbox
  2. 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.
  3. In the console, \n is a newline, \t is a tab, \v is a vertical tab.
  4. Use sep=" " to customize the separator for print output, for example, sep="," will use a comma to separate the printed content.
    Catbox
  5. print('\033[?25l', end="") This statement can turn off the cursor prompt in the console.
  6. print('\033[?25h', end="") This statement can turn on the cursor prompt in the console.
  7. 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")

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.