Python: upper and Lower function do not work

Asked

Viewed 48 times

0

I’m conducting experiments on Python and this time my targets were the functions that handle Strings.

In my tests, I’m trying to make a text converter, however, the functions are not performing their functionality in my Visual Studio Code. The strange thing is that in IDLE conversions occur normally, the problem occurs only in Vscode.

Does anyone know what might be going on?

Follows print.

inserir a descrição da imagem aqui

  • 1

    strings are immutable objects. Check this question: https://answall.com/questions/500210/se-strings-em-python-s%C3%A3o-imut%C3%A1veis-como-conseguimos-alter%C3%A1-la-com-o-m%C3%A9all-repl

  • Although the above question is not 100% exactly identical, the idea is the same: any method that "modifies" the string (such as lower, upper, etc), actually returns another string, so you need to assign the return to some variable (including one of the answers mentions exactly that), and therefore the solution is the same (so I indicated as duplicate)

2 answers

0

I believe you need to declare a new variable by passing the name.upper() in this new and then print or then put the function upper() directly inside the print to work. What is happening is that you are using the upper() and then at the bottom line where you print this is no longer being used.

0

You need to assign to a variable.

Your code can look like this:

name = 'Romulo'
name = name.upper()
print(name)

EXIT: ROMULO

  • 1

    My code is exactly the way you quoted it in your reply, but it still doesn’t work on Vscode. Remembering that in IDLE, with the same pattern, it worked as expected.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.