V
V
vlad192152021-07-29 09:38:52
Python
vlad19215, 2021-07-29 09:38:52

Why is there a "'str' object attribute 'replace' is read-only'" error?

Maybe I'm just stupid, I apologize in advance)
code:

number=input('Введите номер телефона:')
if len(number)==11 and number.isdigit():
  number.replace=str(number.replace)
  number.replace=number.replace(number[0:7],'*')
  print(number.replace)

mistake:
Введите номер телефона:89143434299
Traceback (most recent call last):
  File "d:\python\test.py", line 3, in <module>
    number.replace=str(number.replace)
AttributeError: 'str' object attribute 'replace' is read-only

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
s7on1250, 2021-07-29
@vlad19215

number=input('Введите номер телефона:')
if len(number)==11 and number.isdigit():
    number=number.replace(number[0:7],'*')
print(number)

S
Sergey Gornostaev, 2021-07-29
@sergey-gornostaev

I can’t even imagine what forced you to try to assign its string representation to a method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question