新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:將字典中的所有項(xiàng)目相乘
創(chuàng)新互聯(lián)python教程:

創(chuàng)新互聯(lián)專注于貴德企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站開發(fā),商城網(wǎng)站建設(shè)。貴德網(wǎng)站建設(shè)公司,為貴德等地區(qū)提供建站服務(wù)。全流程按需定制,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
寫一個(gè) Python 程序,用一個(gè)實(shí)際例子將字典中的所有條目相乘。
Python 程序?qū)⒆值渲械乃许?xiàng)目相乘示例 1
在這個(gè) python 程序中,我們使用 For 循環(huán)來迭代字典中的每個(gè)元素。在循環(huán)的 Python 中,我們將這些值乘以總變量。
# Python Program to Multiply All Items in a Dictionary
myDict = {'x': 20, 'y':5, 'z':60}
print("Dictionary: ", myDict)
total = 1
# Multiply Items
for key in myDict:
total = total * myDict[key]
print("\nAfter Multiplying Items in this Dictionary: ", total)
在字典中增加項(xiàng)目的 Python 程序示例 2
這個(gè) python 程序使用 For Loop 和值函數(shù)來相乘字典中的值。
# Python Program to Multiply All Items in a Dictionary
myDict = {'x': 2, 'y':50, 'z':70}
print("Dictionary: ", myDict)
total = 1
# Multiply Items
for i in myDict.values():
total = total * i
print("\nAfter Multiplying Items in this Dictionary: ", total)倍增 Python 字典項(xiàng)輸出
Dictionary: {'x': 2, 'y': 50, 'z': 70}
After Multiplying Items in this Dictionary: 7000 分享文章:Python程序:將字典中的所有項(xiàng)目相乘
文章分享:http://m.fisionsoft.com.cn/article/cdogiid.html


咨詢
建站咨詢
