Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.1K
Views
¿Existe una función integrada en Python 3 como getchar() en C++?

Quiero hacer una entrada de usuario en python, que es similar a la función getchar () utilizada en c ++.

codigo c++:

 #include<bits/stdc++.h> using namespace std; int main() { char ch; while(1){ ch=getchar(); if(ch==' ') break; cout<<ch; } return 0; }

Entrada: desbordamiento de pila

Salida: pila

En el código anterior, cuando una entrada de espacio del usuario se rompe el bucle. Quiero hacer esto en python usando la función de tipo getchar () como lo usé en el código c ++.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Método más fácil:

Solo usa la función de división

 a = input('').split(" ")[0] print(a)

Usando STDIN:

 import sys str = "" while True: c = sys.stdin.read(1) # reads one byte at a time, similar to getchar() if c == ' ': break str += c print(str)

Usando readchar:

Instalar usando pip install readchar

Luego usa el siguiente código

 import readchar str = "" while(1): c = readchar.readchar() if c == " ": break str += c print(str)
over 4 years ago · Santiago Trujillo Report

0

Algo como esto debería hacer el truco

 ans = input().split(' ')[0]
over 4 years ago · Santiago Trujillo Report

0

msvcrt brinda acceso a algunas capacidades útiles en plataformas Windows .

 import msvcrt str = "" while True: c = msvcrt.getch() # reads one byte at a time, similar to getchar() if c == ' ': break str += c print(str)

msvcrt es un módulo incorporado, puede obtener más información en la documentación oficial .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!