0

The below is my code, and as you can guess, I am trying to change the input's first to upper, and rest to lower.

name = input("Your name: ")
name.lower()
name[0].upper()
print(name)

But on the interpreter I get the exact same variable!

  • 2
    Strings are immutable. A **new** string is returned instead. – Martijn Pieters Mar 04 '15 at 18:18
  • 1
    You need to store result into a variable. `l_name=name.lower()` – Kamehameha Mar 04 '15 at 18:19
  • `print(name[0].upper()+name[1:].lower())` – Avinash Raj Mar 04 '15 at 18:19
  • While the linked "duplicate answer" is helpful for people who know what they're doing, I think it may be a step beyond the question here. Is there another question where the answer is simply "Store the result in a variable" instead of "here's why you have to store the result in a variable"? – erewok Mar 04 '15 at 18:23

1 Answers1

4

Its what that str.capitalize is for :

>>> name='name'
>>> name.capitalize()
'Name'

Note that your command name[0].upper() just return the first character in upper mode!

Mazdak
  • 105,000
  • 18
  • 159
  • 188