Thursday, February 5, 2026
HomeLanguagesbase64.b64encode() in Python

base64.b64encode() in Python

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

Syntax : base64.b64encode(string)

Return : Return the encoded string.

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




# import base64
from base64 import b64encode
  
s = b'GeeksForGeeks'
# Using base64.b64encode() method
gfg = b64encode(s)
  
print(gfg)


Output :

b’R2Vla3NGb3JHZWVrcw==’

Example #2 :




# import base64
from base64 import b64encode
  
s = b'I love python'
# Using base64.b64encode() method
gfg = b64encode(s)
  
print(gfg)


Output :

b’SSBsb3ZlIHB5dGhvbg==’

RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32479 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11980 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12066 POSTS0 COMMENTS
Shaida Kate Naidoo
6988 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6936 POSTS0 COMMENTS
Umr Jansen
6919 POSTS0 COMMENTS