str1="This is a Case "
print(str1.swapcase())
print(str1)
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
.
str1="This is a Case "
print(str1.swapcase())
print(str1)
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
.
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()