Good day! As you already understood, the problem with the manipulation of text output. I perform a test task in Python 2.7.

quote = "Π”ΡƒΠΌΠ°ΡŽ, Π½Π° ΠΌΠΈΡ€ΠΎΠ²ΠΎΠΌ Ρ€Ρ‹Π½ΠΊΠ΅ ΠΌΠΎΠΆΠ½ΠΎ Π±ΡƒΠ΄Π΅Ρ‚ ΠΏΡ€ΠΎΠ΄Π°Ρ‚ΡŒ ΡˆΡ‚ΡƒΠΊ ΠΏΡΡ‚ΡŒ ΠΊΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€ΠΎΠ²." print("Π˜ΡΡ…ΠΎΠ΄Π½Π°Ρ Ρ†ΠΈΡ‚Π°Ρ‚Π°: ") print(quote) print("\nОна ΠΆΠ΅ Π² Π²Π΅Ρ€Ρ…Π½Π΅ΠΌ рСгистрС: ") print(quote.upper()) print("\nΠ’ Π½ΠΈΠΆΠ½Π΅ΠΌ рСгистрС: ") print(quote.lower()) print("\nКак Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΎΠΊ: ") print(quote.title()) print("\nΠ‘ малСнькой Π·Π°ΠΌΠ΅Π½ΠΎΠΉ: ") print(quote.replace("ΡˆΡ‚ΡƒΠΊ ΠΏΡΡ‚ΡŒ", "НСсколько ΠΌΠΈΠ»Π»ΠΈΠΎΠ½ΠΎΠ²")) print("\nΠ‘Π½ΠΎΠ²Π° исходная Ρ†ΠΈΡ‚Π°Ρ‚Π°: ") print(quote) raw_input("\nНаТмитС Enter, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π²Ρ‹ΠΉΡ‚ΠΈ ΠΈΠ· ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹.") 

When you start the text output for each option is the same. What is the problem? Thank you in advance for your response.

2 answers 2

Your string is not Unicode. If you want to use Python 2.7, you can add "u" before the quotes, or use the unicode_literals as described above.

 # -*- coding: utf-8 -*- quote = u"Π”ΡƒΠΌΠ°ΡŽ, Π½Π° ΠΌΠΈΡ€ΠΎΠ²ΠΎΠΌ Ρ€Ρ‹Π½ΠΊΠ΅ ΠΌΠΎΠΆΠ½ΠΎ Π±ΡƒΠ΄Π΅Ρ‚ ΠΏΡ€ΠΎΠ΄Π°Ρ‚ΡŒ ΡˆΡ‚ΡƒΠΊ ΠΏΡΡ‚ΡŒ ΠΊΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€ΠΎΠ²." print(u"Π˜ΡΡ…ΠΎΠ΄Π½Π°Ρ Ρ†ΠΈΡ‚Π°Ρ‚Π°: ") print(quote) print(u"\nОна ΠΆΠ΅ Π² Π²Π΅Ρ€Ρ…Π½Π΅ΠΌ рСгистрС: ") print(quote.upper()) print(u"\nΠ’ Π½ΠΈΠΆΠ½Π΅ΠΌ рСгистрС: ") print(quote.lower()) print(u"\nКак Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΎΠΊ: ") print(quote.title()) print(u"\nΠ‘ малСнькой Π·Π°ΠΌΠ΅Π½ΠΎΠΉ: ") print(quote.replace(u"ΡˆΡ‚ΡƒΠΊ ΠΏΡΡ‚ΡŒ", u"НСсколько ΠΌΠΈΠ»Π»ΠΈΠΎΠ½ΠΎΠ²")) print(u"\nΠ‘Π½ΠΎΠ²Π° исходная Ρ†ΠΈΡ‚Π°Ρ‚Π°: ") print(quote) 
  • I apologize, threw off the code without a cap. Always add encoding. The question is closed. Thanks again to everyone! - Alexander Sergeev

The problem is that you are trying to execute Python 3 code on the python2 interpreter.

To fix it, you need to turn the constants into Unicode and declare the source code encoding:

 #!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import unicode_literals # здСсь ваш код бСз измСнСний 

Otherwise, you call .lower() , .upper() , etc for bytes, which may return incorrect results, as you have seen. To work with text, use Unicode:

 >>> print b'я'.upper() #XXX DO NOT DO IT я >>> print u'я'.upper() Я 
  • Thank you for your reply! - Alexander Sergeev