我在用for循环练习,我在这里很菜:p
情况1-
Fruits = ['mango','banana','orange','grapes','apple']
for fruit in Fruits:
print("Current fruit:",fruit)
print("Good Bye")
此代码的输出为
Current fruit: mango
Current fruit: banana
Current fruit: orange
Current fruit: grapes
Current fruit: apple
Good Bye
情况2-
students = ['Avinash','Arush','Akshay','Raghav','Aditya']
for student in students:
print("Current student are:",students)
print("meet you next time")
输出
Current student are: ['Avinash', 'Arush', 'Akshay', 'Raghav', 'Aditya']
Current student are: ['Avinash', 'Arush', 'Akshay', 'Raghav', 'Aditya']
Current student are: ['Avinash', 'Arush', 'Akshay', 'Raghav', 'Aditya']
Current student are: ['Avinash', 'Arush', 'Akshay', 'Raghav', 'Aditya']
Current student are: ['Avinash', 'Arush', 'Akshay', 'Raghav', 'Aditya']
meet you next time
答案 0 :(得分:3)
print("Current student are:",students)
在这里,您要打印整个list
个学生,而不是当前变量student
。应该是
print("Current student are:",student)
这确实有助于拥有不同的变量。