Skip to content
Related Articles

Related Articles

Improve Article

codecs.encode() in Python

  • Last Updated : 26 Mar, 2020

With the help of codecs.encode() method, we can encode the string into the binary form .

Syntax : codecs.encode(string)

 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. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

Return : Return the encoded string.



Example #1 :
In this example we can see that by using codecs.encode() method, we are able to get the encoded string which can be in binary form by using this method.




# import codecs
import codecs
  
s = 'GeeksForGeeks'
# Using codecs.encode() method
gfg = codecs.encode(s)
  
print(gfg)

Output :

b’GeeksForGeeks’

Example #2 :




# import codecs
import codecs
  
s = 'I love python.'
# Using codecs.encode() method
gfg = codecs.encode(s)
  
print(gfg)

Output :

b’I love python.’

My Personal Notes arrow_drop_up
Recommended Articles
Page :