w3resource

Python: Convert an array to an array of machine values and return the bytes representation

Python: Array Exercise-8 with Solution

Write a Python program to convert an array to an array of machine values and return the bytes representation.

Sample Solution:

Python Code :

from array import *
print("Bytes to String: ")
x = array('b', [119, 51, 114, 101,  115, 111, 117, 114, 99, 101])
s = x.tobytes()
print(s)

Sample Output:

Bytes to String:                                                       
b'w3resource'

Python Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Python program to append items from inerrable to the end of the array.
Next: Write a Python program to append items from a specified list.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/array/python-array-exercise-8.php