python - 这些花括号在 python Django 中是什么意思?*{}*
问题描述
我正在做一些代码重构,我遇到了这些坏人。他们的海豚是什么?看起来像格式化程序,但我不太确定。
if data:
result = ''
for recipe_data in data:
url = recipe_data['url']
name = recipe_data['name']
rating = recipe_data['rating']
rating_count = recipe_data['ratingcount']
prep = recipe_data['prep']
cook = recipe_data['cook']
ready_in = recipe_data['ready in']
calories = recipe_data['calories']
result += """
{} {} 卡路里
谢谢。
解决方案
以下是 Python 中花括号的用例:
1.定义字典
my_dict = { 'key': 'value' }
- 定义一个集合
my_set = {1, 2, 3, 4, 5}
- 格式化字符串
message = "My name is {} and I am {} years old".format(name, age)
推荐阅读
- powershell - Get-ADUser:无效类型“System.String[]”
- java - Java spring boot:在嵌套对象中包含嵌套对象属性
- c++ - 类中一种方法的部分特化
- html - 为什么 Typora 导出为 PDF 后 Markdown 中的图像大小会发生变化
- java - ProcessBuilder.start 上的 Java RejectedExecutionException
- c# - 无法将 Squirrel.Windows 的 UpdateManager 集成到 Program.cs
- node.js - 如何使用关键字或标题进行搜索
- python - 比较数据框中标记数据的平均值
- mysql - 从具有多个表的mysql数据库中获取最大(以字节为单位)行
- python - 在模拟期间是否可以使用solve_ivp在每个求解器时间步返回的解向量?