你如何在 f-strings 中创建一个新行?

How do you create a new line in f-strings?

我正在尝试使用 'new_line' 变量使用 python 为变量“profile”创建新行,但我没有成功。

下面的代码不会产生错误。它在一行中给出了所有 3 个字符串,我想要 3 行。

我希望输出看起来像这样,每个字符串换行。

        response: response
        Lat/Lon: 1293.2312,123123.432
        City: New York"
from flask import Flask
from flask import jsonify
import requests
import json
import os


app = Flask(__name__)

@app.route('/change/')
def he():
    API_KEY = "API_KEY"
    CITY_NAME = "oakland"
    url = f"http://api.openweathermap.org/data/2.5/weather?q={CITY_NAME}&appid={API_KEY}"
    response = requests.get(url).json()
    new_line='\n'
    profile = (

        f"response: {response} ============== {new_line}"
        f"Lat/Lon: {response['coord']} ========={new_line}"
        f"City: {CITY_NAME}========{new_line}"
         
    )
   
    return profile 

尝试new_line='</br>'

如果您在浏览器中查看它,它可能会将页面解释为格式错误 HTML 并忽略换行符和空格,因此您需要为此使用标签。