如何在python中处理空输入

2024-03-28 23:48:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个存储输入值的列表。我想如果用户跳过这个问题,列表会得到nan值。你知道吗

我试过这个:

sex=[]
sex.append(input("are you male or female?: "))
while not sex:
    sex.append(np.nan)

但不起作用。我得到这个结果: 性别=[“”,“”]

我怎么处理这个问题?你知道吗


Tags: or用户you列表inputnpnotnan
1条回答
网友
1楼 · 发布于 2024-03-28 23:48:31

你说“南”是什么意思?你知道吗

请尝试一下:

sexArr = []
sexInp = input(">Are you male or female?")
if sexInp:
 sexArr.append(sexInp) 
print(sexArr)

相关问题 更多 >