我如何遍歷一個串列中的值并在另一個串列中使用它們?假設我有一個名為fruit 的串列和另一個名為jobs 的串列
fruit = ['apple','pear','banana']
jobs =['clean the fruit', 'cut the fruit', 'eat the fruit']
我希望它所說的水果是串列水果中的水果。所以它會回傳“清理蘋果”、“清理梨”、“清理香蕉”
uj5u.com熱心網友回復:
用:
fruits = ['apple','pear','banana']
jobs =['clean the fruit', 'cut the fruit', 'eat the fruit']
for job in jobs:
for fruit in fruits:
print(job.replace("fruit", fruit))
輸出
clean the apple
clean the pear
clean the banana
cut the apple
cut the pear
cut the banana
eat the apple
eat the pear
eat the banana
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/347922.html
