Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Masking part of a string

Tags:

python

So my question is, I have an assignment that needs to be solved.

I have a simple function:

def multiplicator(x, y):
    var1 = x * y
    return var1

I need to use this multiplicator to get this result in another function:

Enter: "5435843398429829"     output: "****************9829"

The last 4 digits in the input should not be masked, but the rest should be masked with a "#".


1 Answers

Let us store that number you want to mask in a variable called masked.

unmasked = str(unmasked)
masked = len(unmasked[:-4])*"#"+unmasked[-4:]

I hope this works.

like image 197
Prometheus Avatar answered Oct 30 '25 15:10

Prometheus