[Python] Why doesn't this text.replace function work?

Discussão em 'Python' iniciado por Stack, Junho 13, 2025.

  1. Stack

    Stack Membro Participativo

    I am using text.replace to swap out individual Latin letters for Cyrillic ones. This worked earlier when I used this as a test:

    text = 'The sky is blue' new_text = text.replace('blue', 'red') print(new_text)


    When I run the program it just returns the Latin letters, but doesn't show an error message.

    This is what I tried:

    `text = 'Hello'
    new_text = text.replace('A', 'А')`


    new_text = text.replace('B', 'Б')
    new_text = text.replace('C', 'Ч')
    new_text = text.replace('D', 'Д')
    new_text = text.replace('E', 'Э')
    new_text = text.replace('F', 'Ф')
    new_text = text.replace('G', 'Г')
    new_text = text.replace('H', 'Х')
    new_text = text.replace('I', 'И')
    new_text = text.replace('J', 'Ж')
    new_text = text.replace('K', 'К')
    new_text = text.replace('L', 'Л')
    new_text = text.replace('M', 'М')
    new_text = text.replace('N', 'Н')
    new_text = text.replace('O', 'О')
    new_text = text.replace('P', 'П')
    new_text = text.replace('Q', 'Я')
    new_text = text.replace('R', 'Р')
    new_text = text.replace('S', 'С')
    new_text = text.replace('T', 'Т')
    new_text = text.replace('U', 'У')
    new_text = text.replace('V', 'В')
    new_text = text.replace('W', 'Ю')
    new_text = text.replace('X', 'Ц')
    new_text = text.replace('Y', 'Й')
    new_text = text.replace('Z', 'З')
    new_text = text.replace('a', 'а')
    new_text = text.replace('b', 'б')
    new_text = text.replace('c', 'ч')
    new_text = text.replace('d', 'д')
    new_text = text.replace('e', 'э')
    new_text = text.replace('f', 'ф')
    new_text = text.replace('g', 'г')
    new_text = text.replace('h', 'х')
    new_text = text.replace('i', 'и')
    new_text = text.replace('j', 'ж')
    new_text = text.replace('k', 'к')
    new_text = text.replace('l', 'л')
    new_text = text.replace('m', 'м')
    new_text = text.replace('n', 'н')
    new_text = text.replace('o', 'о')
    new_text = text.replace('p', 'п')
    new_text = text.replace('q', 'я')
    new_text = text.replace('r', 'р')
    new_text = text.replace('s', 'с')
    new_text = text.replace('t', 'т')
    new_text = text.replace('u', 'у')
    new_text = text.replace('v', 'в')
    new_text = text.replace('w', 'ю')
    new_text = text.replace('x', 'ц')
    new_text = text.replace('y', 'й')
    new_text = text.replace('z', 'з')
    print(new_text)\`


    This is what I expected:

    Хэлло

    But this is what I got:

    Hello

    Continue reading...

Compartilhe esta Página