Advertisement
# Signature of swapcase() method
swapcase()
# Python - Method swapcase() Example
# Creating a string
s1 = ('Did you know that Moon is not a planet?')
# Printing the original string
print('Value of string : ', s1)
# Calling the swapcase() method on string object
print('Calling the swapcases() method on string : ', s1.swapcase())
Value of string : Did you know that Moon is not a planet?
Calling the swapcases() method on string : dID YOU KNOW THAT mOON IS NOT A PLANET?
# Python - Method swapcase() Example
# Creating a string
s1 = ('MERCURY - A planet closest to the Sun')
# Printing the original string
print('Original string before calling swapcase() : ', s1)
# Calling the swapcase() method on string object
print('Calling the swapcase() method : ', s1.swapcase())
# Printing the original string
print('Original string after calling swapcase() : ', s1)
String's value : Jupiter - MERCURY - A planet closest to the Sun
Calling the swapcase() method : mercury - a PLANET CLOSEST TO THE sUN
Original string after calling swapcase() - MERCURY - A planet closest to the Sun
Advertisement
# Python - swapcase() method example.
# Creating a string
s = 'In Life, Good things don\'t come easy'
# Printing the original string
print('Original string is : ', s)
# Result of calling swapcase() is made to reference by the reference of original string.
s= s.swapcase()
# Old reference variable pointing to the new string
print('String value after swapcase() : ', s)
Original string is : In Life, good things don't come easy
String value after swapcase() : iN lIFE, GOOD THINGS DON'T COME EASY
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement