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.



Follow us on Facebook and Twitter for latest update.