Taking user Input without showing the Text in Python

avatar

Borislav Hadzhiev

Last updated: Aug 24, 2022

banner

Photo from Unsplash

Taking user Input without showing the Text in Python #

Use the getpass() method to take user input without showing the text, e.g. result = getpass.getpass('Enter your password: '). The getpass method prompts the user for a password without echoing.

main.py
import getpass result = getpass.getpass('Enter your password: ') print(result)

take user input without showing text

We used the getpass() method from the getpass module to prompt the user for input without echoing.

The getpass module is available in the standard library, so you don't have to install anything.

The getpass method is usually used to prompt the user for a password or other sensitive information.

The argument the method takes is the message that is displayed to the user.

If no message is provided, it defaults to "Password: ".

main.py
import getpass result = getpass.getpass() print(result)

input without showing text default message

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.