Categories
Python Answers

How to convert string to binary with Python?

Spread the love

Sometimes, we want to convert string to binary with Python.

In this article, we’ll look at how to convert string to binary with Python.

How to convert string to binary with Python?

To convert string to binary with Python, we call the encode method.

For instance, we write

b = "hello world".encode('ascii')                           

to call 'hello world'.encode with 'ascii' to get an ASCII binary string with the same content.

Conclusion

To convert string to binary with Python, we call the encode method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *