Compress and decompress string in Python

0 votes
Please write a program to compress and decompress the string. Which module should be used?
Jul 23, 2019 in Python by Ritu
12,295 views

1 answer to this question.

0 votes

You can use the zlib module available in python to compress and decompress the string. Refer to the code below:

import zlib
text="Hello world"
comp=zlib.compress(text)
print("Compressed: ", comp)
decomp=zlib.decompress(text)
print("Decompressed: ", decomp)


This should work.

To know more, It's recommended to join our Python Training in Chennai today.

answered Jul 23, 2019 by Bhagavath

edited Oct 7, 2021 by Sarfaraz

Related Questions In Python

0 votes
1 answer

How can I print variable and string on same line in Python?

Use , to separate strings and variables while printing: print ...READ MORE

answered Sep 17, 2018 in Python by Priyaj
• 58,090 points
3,279 views
0 votes
1 answer

Is it possible to print a string and a variable in a single print statement in Python?

This can be done using simple string ...READ MORE

answered Jul 15, 2019 in Python by Neel
• 3,020 points
587 views
+1 vote
1 answer
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 3,983 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,356 views
+1 vote
1 answer

Python: Print variable and string in same line

For a better understanding you can refer ...READ MORE

answered Oct 30, 2018 in Python by Priyaj
• 58,090 points
1,211 views
0 votes
2 answers

What's the difference between %s and %d in Python string formatting?

The reason is that they are using ...READ MORE

answered Feb 8, 2022 in Python by Rahul
• 9,670 points
19,245 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP