Discuss / Python / 这个哪里出错了呀

这个哪里出错了呀

Topic source

F1shMAN-

#1 Created at ... [Delete] [Delete and Lock User]

L = ['Bart', 'Lisa', 'Adam']
a=['a','b','c']
for x in L:
for y in a:
print('hello,%s and %s'%y%x)

雾是成风

#2 Created at ... [Delete] [Delete and Lock User]

最后一行写成这样就行啦,供参考 print('hello,%s and %s'%(y,x))

梅尔加尼

#3 Created at ... [Delete] [Delete and Lock User]

L = ['Bart', 'Lisa', 'Adam'] for name in L: print('Hello, %s!' % name)

片霧魂

#4 Created at ... [Delete] [Delete and Lock User]

梅尔加尼最后一行多此一举了,for in是将L中的内容逐个打印的

L = ['bart','lisa','adam'] for i in L: print('hello,',i)

输出结果: hello, bart hello, lisa hello, adam


  • 1

Reply