w3resource

Python: Create a bytearray from a list


Create Bytearray from List

Write a Python program to create a bytearray from a list.

Sample Solution:

Code:

# Print a blank line for separation.
print()

# Create a list of integers called nums.
nums = [10, 20, 56, 35, 17, 99]

# Create a bytearray from the list of integers.
values = bytearray(nums)

# Iterate through the elements of the bytearray and print each element.
for x in values:
    print(x)

# Print a blank line for separation.
print()

Sample Output:

10                                                                                                            
20                                                                                                            
56                                                                                                            
35                                                                                                            
17                                                                                                            
99

Python Code Editor:

 

Previous: Write a Python program to prove that two string variables of same value point same memory location.
Next: Write a Python program to round a floating-point number to specified number decimal places.

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.