Append and replace

Why ther eis requirement if assignment to make replace function work like this
four = four.replace(“0b”,"")
while in lists, a simple .append does the work without reassigning.

Type your question above this line.


Hello @Mohammad_Alim

This behavior is due to the internal working of Python. .append method of the list works in-place whereas the .replace method does not. Hence, to reflect the changes in the original variable that is four, we have to re-assign it the replaced value.

Hope this helps!