我想在 python 中进行用户输入,这类似于c++ 中使用的getchar()函数。
C++代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
char ch;
while(1){
ch=getchar();
if(ch==' ') break;
cout<<ch;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输入:堆栈溢出
输出:堆栈
在上面的代码中,当用户输入一个空格时,循环会中断。我想使用我在 c++ 代码中使用的getchar()类型函数在 python 中执行此操作。