Skip to main content
 首页 » 编程设计

python之为什么我的 Python Interactive shell 中的列表推导会附加一个 Nones 列表

2025年05月04日15shihaiming

<分区>

我正在我的交互式 shell 中测试一些 Django 功能

这是我尝试探测这些对象,注意末尾的 Nones 列表

>>> [print(foo) for foo in CharacterSkillLink.objects.all() if foo.speciality] 
Streetwise (Street Countdown) Roran 
[None] 

还有更正统的列表理解:

>>> [print(foo) for foo in range(1,10)] 
1 
2 
3 
4 
5 
6 
7 
8 
9 
[None, None, None, None, None, None, None, None, None] 

九个无,全部排成一行。

为什么我会得到那个?