Related Articles

Related Articles

zlib.compress(s) in python
  • Last Updated : 06 Mar, 2020

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

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

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output :

43
49



Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output :

22
27

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :