gpt4 book ai didi

python 函数获取使用 input() 函数读取的值的数量

转载 作者:行者123 更新时间:2023-12-01 05:38:59 25 4
gpt4 key购买 nike

在C语言中,scanf()函数将返回读入变量的数据数量。是否可以使用Python中的input()函数获取读取的变量数量?例如。

v = scanf("%d%d%d", &a, &b, &c);

返回使用scanf()函数读取的整型变量的数量。如果三个变量值不是整数,它将返回小于三的值。

最佳答案

您可能需要

len(raw_input().split())

它不会检查参数是否为整数。您可以使用

numbers = map(int, raw_input().split())

将输入转换为整数。如果格式错误,您将收到异常 (ValueError)

关于python 函数获取使用 input() 函数读取的值的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18132030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com