两个或者三个以上列表和字符串的相加拼接

三个以上列表和字符串的相加拼接

>>> p=  ['jack','andy','kenny']
>>> s='hello'
>>> p1=['Mary','Hellen','Ken']
>>> for i in range(len(p)):
	w=s+p[i]+','+s+p[i]+'.'
	print(w)

	
helloMary,helloMary.
helloHellen,helloHellen.
helloKen,helloKen.


>>> for i in range(len(p)):
	w=s+' '+p[i]+','+s+' '+p[i]+'.'
	print(w)

	
hello Mary,hello Mary.
hello Hellen,hello Hellen.
hello Ken,hello Ken.
>>> 
>>> 

一个列表和一个字符串的相加

l =  ['jack','andy','kenny']
 
s = 'Hello'
 
[s + i for i in l]
Out[3]: ['Hellojack', 'Helloandy', 'Hellokenny']
 
[s + ' ' + i for i in l]
Out[4]: ['Hello jack', 'Hello andy', 'Hello kenny']

listS =  ['jack','andy','kenny']
s = 'Hello'
for i in range(len(listS)):
    listS[i] = s+listS[i]
print listS

猜你喜欢

转载自blog.csdn.net/hellenlee22/article/details/89878711