二手产品经理

二手产品经理

THIS IS RENO

Learn Python Online in 100 Days - Week 5, Day 2

Record#

  1. Learn about the format in print. The format is as follows:
  2. One way is to replace the variable's position with {} and write the variables in order in the format at the end.
    Catbox
  3. Another way is to write a string in {}, such as {name}, and use string = variable in the format at the end, such as name=name. This way, you don't need to consider the position of the variable.
    Catbox
  4. There is also a f-string syntax, which looks simpler. Just use f" at the beginning, and use {variable name} directly 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. The f format is an abbreviation of format. That is, print(f"") = print("".format())
  8. ChatGPT says: format() is a built-in function used to insert values into the 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 a 30-day reflection question 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.