二手产品经理

二手产品经理

THIS IS RENO

Learn Python Online in 100 Days - Week 5 Day 2

Record#

  1. Learn the format in print. The format is as follows:
  2. One way is to simply replace {} with the position of the variable, and write the variables in order in the final format.
    Catbox
  3. Another way is to write a string in {}, such as {name}, and use string = variable in the final format, such as name=name, so you don't need to consider the position of the variable.
    Catbox
  4. There is also an f-string syntax, which looks simpler. Just use f" at the beginning, and you can directly use {variable name} in the string.
    Catbox
  5. The f format can also control the alignment of the print: left = <, right = >, center = ^. The number after the symbol means align how many characters, for example: <30, which means left align 30 characters.
  6. format can not only be used after print, but also after assignment, it feels like a way to format text and variables.
  7. f format is the abbreviation of format. That is, print(f"") = print("".format())
  8. chatgpt says: format() is a built-in function used to insert values into placeholders in a string. It provides a more flexible and dynamic way to create formatted strings. You can use curly braces {} as placeholders, and then pass the corresponding values through the format() function.
  9. Today's exercise is to create a response to the thoughts of the 30th day, and center align it.

CODE#

print("30 Days Down")
for i in range(1, 30):
  r = input(f"Day {i}\n")
  t = f"You thought Day {i} was "
  print(f"{t: ^40}")
  print(f"{r: ^40}")
  print()
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.