Python: Read a string and interpreting the string as an array of machine values
Python: Array Exercise-22 with Solution
Write a Python program that reads a string and interprets it as an array of machine values.
from array import array import binascii array1 = array('i', [7, 8, 9, 10]) print('array1:', array1) as_bytes = array1.tobytes() print('Bytes:', binascii.hexlify(as_bytes)) array2 = array('i') array2.frombytes(as_bytes) print('array2:', array2)
array1: array('i', [7, 8, 9, 10]) Bytes: b'0700000008000000090000000a000000' array2: array('i', [7, 8, 9, 10])
Python Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join