ee.Dictionary.get

Trích xuất một giá trị có tên từ một từ điển. Nếu từ điển không chứa khoá đã cho, thì defaultValue sẽ được trả về, trừ phi khoá đó có giá trị rỗng.

Cách sử dụngGiá trị trả về
Dictionary.get(key, defaultValue)Đối tượng
Đối sốLoạiThông tin chi tiết
this: dictionaryTừ điển
keyChuỗi
defaultValueĐối tượng, mặc định: null

Ví dụ

Trình soạn thảo mã (JavaScript)

// A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
var dict = ee.Dictionary({
  B1: 182,
  B2: 219,
  B3: 443
});

print('Value for "B1" key', dict.get('B1'));

// Set a default value for the case where the key does not exist.
print('Value for nonexistent "Band_1" key',
      dict.get({key: 'Band_1', defaultValue: -9999}));

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap cho quá trình phát triển tương tác.

import ee
import geemap.core as geemap

Colab (Python)

# A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
dic = ee.Dictionary({
    'B1': 182,
    'B2': 219,
    'B3': 443
})

print('Value for "B1" key:', dic.get('B1').getInfo())

# Set a default value for the case where the key does not exist.
print('Value for nonexistent "Band_1" key:',
      dic.get(**{'key': 'Band_1', 'defaultValue': -9999}).getInfo())