Python:Pillow .getbands()

mariosKontis3257040938's avatar
Published Mar 25, 2025
Contribute to Docs

In the Pillow library, the .getbands() method returns a tuple that contains the name of each band in an image. For example, for a CMYK image, .getbands() will return ('C', 'M', 'Y', 'K').

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours

Syntax

Image.getbands()

Parameters:

The .getbands() method does not take any parameters.

Return Value:

Returns a tuple of strings, where each string represents the name of a color band in the image.

Example

The image to be used for this example is:

Input image to perform the .getbands() operation

In this example, the .getbands() method returns the band names of the example image:

from PIL import Image
# Opening the image file
img = Image.open("samandgos.jpg")
# Getting the band names
bands = img.getbands()
print(bands)

The above code produces the following output:

('R', 'G', 'B', 'A')

All contributors

Contribute to Docs

Learn Python:Pillow on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours