Open In App

gzip.compress(s) in Python

Last Updated : 23 Mar, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

With the help of gzip.compress(s) method, we can get compress the bytes of string by using gzip.compress(s) method.

Syntax : gzip.compress(string)
Return : Return compressed string.

Example #1 :
In this example we can see that by using gzip.compress(s) method, we are able to compress the string in the byte format by using this method.




# import gzip and compress
import gzip
  
s = b'This is GFG author, and final year student.'
print(len(s))
  
# using gzip.compress(s) method
t = gzip.compress(s)
print(len(t))


Output :

43
61

Example #2 :




# import gzip and compress
import gzip
  
s = b'GeeksForGeeks@12345678'
print(len(s))
  
# using gzip.compress(s) method
t = gzip.compress(s)
print(len(t))


Output :

22
39


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads