zlib.decompress(s) in Python

Last Updated : 6 Mar, 2020
With the help of zlib.decompress(s) method, we can decompress the compressed bytes of string into original string by using zlib.decompress(s) method.
Syntax : zlib.decompress(string) Return : Return decompressed string.
Example #1 : In this example we can see that by using zlib.decompress(s) method, we are able to decompress the compressed string in the byte format of string by using this method. Python3 1=1
# import zlib and decompress
import zlib


s = b'This is GFG author, and final year student.'
 
# using zlib.compress(s) method
t = zlib.compress(s)
print("Compressed String")
print(t)

print("\nDecompressed String")
print(zlib.decompress(t))
Output :
Compressed String b'x\x9c\x0b\xc9\xc8,V\x00"w7w\x85\xc4\xd2\x92\x8c\xfc"\x1d\x85\xc4\xbc\x14\x85\xb4\xcc\xbc\xc4\x1c\x85\xca\xd4\xc4"\x85\xe2\x92\xd2\x94\xd4\xbc\x12=\x00A\xc9\x0f\x0b' Decompressed String b'This is GFG author, and final year student.'
Example #2 : Python3 1=1
# import zlib and decompress
import zlib


s = b'GeeksForGeeks@12345678'
 
# using zlib.compress(s) method
t = zlib.compress(s)
print("Compressed String")
print(t)

print("\nDecompressed String")
print(zlib.decompress(t))
Output :
Compressed String b'x\x9csOM\xcd.v\xcb/r\x07\xd1\x0e\x86F\xc6&\xa6f\xe6\x16\x00X\xf6\x06\xea' Decompressed String b'GeeksForGeeks@12345678'
Comment