简体   繁体   English

如果列表为空,则返回 None

[英]Return None if list is empty

I have this function:我有这个 function:

def get_min(int_list):
    if len(int_list) == 0:
        return None

Basically, if an empty list is passed, it should return "None" in the terminal:基本上,如果传递了一个空列表,它应该在终端中返回“None”:

python3 -i PA03.py
get_min([])

As I said, it should return "None" in the console but it's printing nothing.正如我所说,它应该在控制台中返回“无”,但它什么也没打印。 I'm not allowed to use print().我不允许使用 print()。

You must return "None" and you can use this:您必须return "None" ,您可以使用它:

import sys
sys.stdout.write(get_min([]))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM