如何让文本行在 python 中消失

How to make lines of text go away in python

所以我有这个需要密码的代码。

password = input('Enter your password: ')
if password == 'yellow':
    print('You have made it inside the computer')

但我想让它在我按回车键时,显示“输入您的密码:黄色”的行将消失。我查了这个并访问了很多网站,但其中 none 个回答了我的问题。至少,我想知道如何使它在我输入“黄色”时显示为“******”或类似的东西。

为此您需要外部库。参见 this one

例如

import getpass 
  
p = getpass.getpass(prompt='Your favorite flower? ') 
  
if p.lower() == 'rose': 
    print('Welcome..!!!') 
else: 
    print('The answer entered by you is incorrect..!!!') 

导入 getpass 模块。

import getpass 

password = getpass.getpass('Enter your password: ')
if password == 'yellow':
    print('You have made it inside the computer')