4

I want to take one letter at a time in python. can we take one letter at a time using "input()" in python3

Example: I want to input only one letter such as a. b, c, .....etc. It should not accept more than one letter word such as ab, as, asa ... etc. is there any such function in python 3?

bhargav
  • 49
  • 1
  • 1
  • 2

2 Answers2

3

Use the getch module.

import getch
# ...
char = getch.getch() # User input, but not displayed on the screen
# or
char = getch.getche() # also displayed on the screen
blhsing
  • 91,368
  • 6
  • 71
  • 106
0

You can use this code:

a=input()[0]
print(a)

a will be first char but if you want to force user to enter one letter you can use getch