[Python] Is there a built-in function in Python 3 like getchar() in C++?

Discussão em 'Python' iniciado por Stack, Fevereiro 27, 2025.

  1. Stack

    Stack Membro Participativo

    I want to do user input in python which is similar to getchar() function used in c++.

    c++ code:

    #include<bits/stdc++.h>

    using namespace std;
    int main()
    {
    char ch;
    while(1){
    ch=getchar();
    if(ch==' ') break;
    cout<<ch;
    }
    return 0;
    }


    Input: stack overflow

    Output: stack

    In the above code, when a space input from the user than the loop breaks. I want to do this in python using getchar() type function as I used in c++ code.

    Continue reading...

Compartilhe esta Página