Converting to upper case. Which way is more pythonic?

Zefi picture Zefi · Jan 7, 2012 · Viewed 75.7k times · Source

Using Python 3. Which method is more Pythonic? Converting to uppercase:

guess = input("\n\nEnter your guess: ")
guess = guess.upper()
print(guess)

or

guess = input("\n\nEnter your guess: ").upper()
print(guess)

or

guess = input("\n\nEnter your guess: ")
print(guess.upper())

I'd also really like to know any other more efficient ways of writing this. Thanks, really appreciate the advice.

Answer

brandizzi picture brandizzi · Jan 7, 2012

It may eventually depend upon what you will do with the value but, frankly, any of these solutions is equally pythonic almost in any situation. Just use any one of them and go ahead to the real beef :)