例如,我有以下内容:
first_count = 5000
query = '''
{
students(first: first_count) {
id
firstName
college {
id
name
location
rating
}
}
}
'''
在查询的第二行中,first_count 应该是一个变量,但不幸的是我很难使其动态化。我想做一个 f 字符串,但我丢失了多行字符串并且还使用了转义字符。有什么方法可以在此字符串中插入变量以使其动态,同时保持多行格式?
是的,你可以这样解决:
first_count = 5000
query = f'''
{{
students(first: {first_count}){{
id
firstName
college {{
id
name
location
rating
}}
}}
}}
'''
print(query)