-1
str1="This is a Case "
print(str1.swapcase())
print(str1)

Results

I expect the output for both print statements to be swapped as: "tHIS IS A cASE" but the output for first print is "tHIS IS A cASE" and second print is the original str1.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880

1 Answers1

1

swapcase doesn't change the string that you call it on, it returns a new string. If you want to change the original string, you have to reassign it with the returned value.

str1 = str1.swapcase()
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880