Njo*_*joi -2 python python-3.x
我有要在其中并排打印两个字符串的代码
hp
ea
lu
ll
o
Run Code Online (Sandbox Code Playgroud)
但是我无法打印它们,我该如何修改给定的代码,我的代码是
s1='hello'
s2='paul'
i=0
while i<len(s1) and i<len(s2):
print(s1[i],s2[i])
i+=1
Run Code Online (Sandbox Code Playgroud)
这是使用的变体itertools.zip_longest
:
from itertools import zip_longest
s1='hello'
s2='paul'
for a, b in zip_longest(s1, s2, fillvalue=' '):
print(a, b)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
79 次 |
最近记录: |