9 月 152020
 
#字符串的方法method
phone_number = '138-1234-5678'
hiding_number = phone_number.replace(phone_number[4:8], '*' * 4)
#第3-7个字符,不含第7个字符,即1234,替换为*,连续4个
print(hiding_number)
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python38/python.exe c:/Users/harveymei/hello.py
138-****-5678
PS C:\Users\harveymei>

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)