GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • w3resource
  • Front End
  • HTML
  • CSS
  • JavaScript
  • HTML5
  • Schema.org
  • php.js
  • Twitter Bootstrap
  • Responsive Web Design tutorial
  • Zurb Foundation 3 tutorials
  • Pure CSS
  • HTML5 Canvas
  • JavaScript Course

This view

  • Original page
  • New address

GeezerVison is showing www.w3resource.com — Python: Create a bytearray from a list - w3resource

Python: Create a bytearray from a list

Last update on May 17 2025 05:44:17 (UTC/GMT +8 hours)


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

For more Practice: Solve these Related Problems:

  • Write a Python program to create a bytearray from a given string.
  • Write a Python program to modify a bytearray by changing a specific byte.
  • Write a Python program to convert a bytearray to a list of integers.
  • Write a Python program to encode a string into a bytearray and then decode it back.

Go to:

  • Python Basic Exercises Home ↩
  • Python Exercises Home ↩

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.

Python Code Editor:

 

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.


  • Daily Coding Challenges & Projects
  • Weekly Trends and Language Statistics



You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.