Replacing a character from a certain index

How can I replace a character in a string from a certain index? For example, I want to get the middle character from a string, like abc, and if the character is not equal to the character the user specifies, then I want to replace it.

Something like this maybe?

middle = ? # (I don't know how to get the middle of a string)

if str[middle] != char:
    str[middle].replace('')

Leave a Comment