[Python] How to modify a "Name+2nd name+Surname without touch 2nd name? Phyton

Discussão em 'Python' iniciado por Stack, Agosto 28, 2025.

  1. Stack

    Stack Membro Participativo

    I want to change 2 characters in a variable in phyton but when I fix one the other change again.

    I have this variable.

    name= " rIana Danyela RodrYguez "


    I don't want to touch the name "Danyela".

    If i want to replace "I" in "rIana" by "Y" and "Y" in "RodrYguez" by "i" I made this line.

    .print(nombre.strip() delete spaces

    .lower() lower all letters.

    .title() Capitalizes 1st letter of each word.

    then .replace ("i","y",)) of riana gives me "ryana"

    BUT,when I try to replace "y" in rodyguez with .replace ("y","i",) I get rodriguez but "ryana" becomes "riana" again. The I got a loop when I try to fix it.

    I found that i can try to change "RodrYguez" first with

    print(nombre.strip().replace("Y", "i").lower().title().replace ("i","y", 1,))


    then I got my solution but I want to replace this caracters words in 1 move.

    Continue reading...

Compartilhe esta Página