擅长:python、mysql、java
<p>所以我想你是在要求列表中的前三个元素,索引0,1,2。所以,虽然你所做的是有效的,但这种方式更好。你知道吗</p>
<p><strong>切片</strong>-每个python程序员应该知道的常见函数:</p>
<p>“切片:</strong><a href="https://docs.python.org/3/library/functions.html#slice" rel="nofollow noreferrer">https://docs.python.org/3/library/functions.html#slice</a>的Python文档</p>
<p>“限制查询集”的Django文档:</p>
<p>将从未输入的第0个索引开始获取前三个元素。括号也可以是<code>[0:3]</code>。你知道吗</p>
<pre><code>special_list = Special.objects.filter(
promotion=False,
start__lte=date_instance,
minimum_stay__lte=nights,
object_id=room_filter.id,
end__gte=date_instance,
is_active=True,
member_deal=False
)[:3]
</code></pre>