Python 中不显示输入

Pyt*_*n03 5 python passwords python-3.x python-3.6

我想问一下我们可以对输入函数进行哪些更改,以便我们输入的任何内容都表示为“*”。正如我们都看到的那样,当我们在登录页面上输入密码时,它会被写为 *** **** .这可以用 python 完成吗?像这样的东西:

Python 3.6.6 (v3.6.6:4cu1f74eh7, Jun 27 2018, 02:47:15) [MSC v.1900 64 bit 
(Intel)] on win64
Type "copyright", "credits" or "license()" for more information.
>>> a = input('Write your password here:')
Write your password here: ************* # we write our password
>>> print(a)
stackoverflow
Run Code Online (Sandbox Code Playgroud)

该功能getpass不起作用并且也发出警告。

arg*_*rgo 5

您可以使用以下库来执行此操作

import getpass

pswd = getpass.getpass('Write your password here:')
print(pswd)
Run Code Online (Sandbox Code Playgroud)