Single character input? | Sololearn: Learn to code for FREE!


Single character input?

How to make single character input in python?like getch() is there any function in python

4/13/2020 1:32:23 PM


7 Answers

New Answer


If you just want to work without using Return-key, there seems to be no easy way. But you can check this post, there are several approaches explained:


Type only one char in the input. It will still be taken as string. ch = ord(input()[0]) will gjve you ascii value of the first char. To convert back print(chr(ch)) # convert the ascii value to char but still represented as string


rodwynnejones I realized there is no point in doing that since the value stored is still of type "string". Better type only single char(string)


swim....ah...didn't notice you already had the [0] in you original response..forgive me. I just realised what Lilas was looking for....(although a python version) When using getch() from the conio header file..there is no need to hit "enter" after entering a code snippet doesn't do that.....sorry Lilas.


thanks for help But i have to press enter after that.any other solution plz


Wasn't sure if this would work...but... had a go and it does actually work.. myinput = input()[0] print(myinput)