gpt4 book ai didi

python - 如何在python中同时插入多个输入?

转载 作者:行者123 更新时间:2023-12-03 06:57:52 29 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Two values from one input in python?

(19 个回答)


1年前关闭。




我对 C++ 的经验很少,并且有一个我非常喜欢的函数:
(这是一个只有加法的计算器的简单示例)

#include <iostream>
using namespace std;

int main(){
int a, b;
cout << "insert numbers and calculations" << endl;
cin >> a >> b;
cout << a + b << endl;
return 0;
}
我真的很喜欢 cin系统,因为您可以同时有多个输入。但是在 Python 上,我同时只有一个这样的:
float a = 0
float b = 0
a = input("insert fist number")
b = input("insert the second number")
print(a + b)
我想找到一种同时拥有多个输入的方法,类似于 cin句法。这个问题的解决方案是什么?

最佳答案

你可以试试这个方法

a, b = [int(x) for x in input("Enter two values: ").split()] 
print("First Number is: ", a)
print("Second Number is: ", b)
print()

关于python - 如何在python中同时插入多个输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63918910/

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