起因
for循環遍歷出 對象(字典、列表、字符串···) 的 鍵/值
For循環
- 遍歷鍵
dict = {'Name': 'Runoob', 'Age': 7}
for i in dict:
print(i)
- 遍歷值
dict = {'Name': 'Runoob', 'Age': 7}
for i in dict.values()
print(i)
- 遍歷鍵和值
dict.items()
for key,value in dict.items():
print(key)
print(value)
- 取列表中的第一個大字典 中 各個小字典的 鍵和值
latest_list = latest_platform[0].to_dict() # 取列表第一個值.轉換成字典
for key1, value1 in latest_list.items(): # items()以列表返回可遍歷的(鍵, 值) 元組數組
# print(key1)
# print(value1)
if key1 == 'id':
platform_id = value1
if key1 == "task_category_id":
task_category_id = value1
if key1 == "target_image_category_id":
target_image_category_id = value1
if key1 == "platform_key":
platform_key = value1