Solved

Why doesn't upper() change my variable?

SophieDevOP
name = "apollo"
name.upper()
print(name)   # still apollo
1

Comments 4

Join the discussion

Already have an account? Log in

  1. FreyaL Solutionreplies: 2

    String methods return a new string; the original never changes (strings are immutable). Assign the result:

    name = name.upper()
    9
    1. SophieDevOPreplies: 1

      That's a big "aha". So no string method changes the string itself?

      0
      1. MateoG

        Correct, none of them. Lists are different: list.sort() changes the list in place and returns None. That trips people the other way.

        6
    2. TomBecker

      There's even a challenge about that, "Strings don't change" šŸ˜„

      1