第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何打印字典的標題?

如何打印字典的標題?

翻翻過去那場雪 2022-09-27 10:51:01
代碼ralph = {'type': 'cat','owner': 'mark'}lucy = {'type': 'cat','owner': 'carrie'}pets = [ralph, lucy]for pet in pets:    print(str(pet))    owner = pet['owner']    print('pet type: ' + pet['type'] + '\n' + 'owner: ' + owner.title())提供輸出:{'type': 'cat', 'owner': 'mark'}pet type: catowner: Mark{'type': 'cat', 'owner': 'carrie'}pet type: catowner: Carrie我試圖打印每只寵物的名字(拉爾夫和露西)
查看完整描述

1 回答

?
慕哥6287543

TA貢獻1831條經(jīng)驗 獲得超10個贊

您正在嘗試訪問變量名稱。雖然這在原則上是可能的,但您不想這樣做。


我假設你正在嘗試這樣的想法:


pet1 = {'type': 'cat','owner': 'mark', 'name': 'ralph'}

pet2 = {'type': 'cat','owner': 'carrie', 'name': 'lucy'}

pets = [pet1, pet2]


for pet in pets:

    print('pet name: ' + pet['name'])


查看完整回答
反對 回復 2022-09-27
  • 1 回答
  • 0 關注
  • 78 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號