You can use the zlib module available in python to compress and decompress the string. Refer to the code below:
print("Compressed: ", comp)
print("Decompressed: ", decomp)
This should work.
To know more, It's recommended to join our Python Training in Chennai today.