举个例子,就这个题:
字符串s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',假如希望输出s的前20个字符,而不是所有字符 s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' num = 1 for ch in s: if num > 20: break print(ch) num = num + 1
这是用break输出的20个字符,能不能纯粹用while循环来输出啊,应该怎么写?
s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
num=0
while num<20:
print(s[num])
num = num + 1