0

I am new to programming and I want to know if I can replace what I write when I run the program with '*'. For example if I write "password", I see in the console "********" but in the system it keeps being "password". I know that there is a way in C# but I don't find it in Python.

  • 1
    Have you considered the `getpass` module? It doesn't do exactly the same thing, but it does hide your password as it's being typed in the console. – fluffyyboii Jul 09 '22 at 00:28

1 Answers1

-2

You can't replace it in the system, but you can replace it in the system output. You could use the print() function to write the output to the screen, and you can use the string's replace() method to replace the desired characters with '*'s, like so:

print('password'.replace('password', '*' * len('password')))
# ******
Soufian
  • 90
  • 4
  • 1
    I don't see how this is useful in *any* sort of way. OP might as well do `print('******')`. This also does not answer the question. OP asks about taking input from a user – DeepSpace Jul 09 '22 at 00:33