firstName = ['abcd','efghi','jkl','mnopqr']
lastName = ['xyz','pqrst','uvw','klmn']
我想要的输出是
abcd xyz a.xyz@example.com
efghi pqrst e.pqrst@example.com
jkl uvw j.uvw@example.com
mnopqr klmn m.klmn@example.com
我尝试了各种各样的方法并且失败了。我能想出的最接近的是
for x,y in zip(firstName,lastName):
print(x,y)
我该怎么办?
答案 0 :(得分:2)
使用基本字符串格式并打印输出,如下所示:
for x, y in zip(firstName,lastName):
print(x, y, "%s.%s@example.com"%(x[0], y))
答案 1 :(得分:2)
>>> for x,y in zip(firstName,lastName):
... print("{0}\t{1}\t{2}".format(x,y,x[0]+'.'+y+'@example.com'))
...
abcd xyz a.xyz@example.com
efghi pqrst e.pqrst@example.com
jkl uvw j.uvw@example.com
mnopqr klmn m.klmn@example.com
答案 2 :(得分:2)
这将打印您正在寻找的输出。你真的只想打印吗?
<html ng-app="myApp" ...
答案 3 :(得分:1)
firstName = ['abcd','efghi','jkl','mnopqr']
lastName = ['xyz','pqrst','uvw','klmn']
for index in range(0, len(firstName)):
first = firstName[index]
last = lastName[index]
email = first[0] + '.' + last + '@example.com'
print first, last, email
答案 4 :(得分:1)
for i,j in zip(firstName,lastName):
print (i+" "+j+" "+i[0]+"."+j+"@example.com")
输出
abcd xyz a.xyz@example.com
efghi pqrst e.pqrst@example.com
jkl uvw j.uvw@example.com
mnopqr klmn m.klmn@example.com