프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다.
전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자를 전부 *으로 가린 문자열을 리턴하는 함수, solution을 완성해주세요.
처음 시도:
def solution(phone_number):
stars = '*' * (len(phone_number) - 4)
nums = phone_number[-4:]
return f'{stars}{nums}'
string[start:end:step]: 문자열 슬라이싱으로 문자열의 원하는 부분만 뽑아낼 때 사용한다
ex1)
m = 'hello world'
print(m[-4:]) #orld
ex2)
m = 'hello world'
print(m[4:]) #o world