from __future__ import print_function
s='stackoverflow'
for i in range(0,len(s),5):
if (int(i%2) == 0):
print ( s[i:i+5].lower() ,end = "")
else:
print (s[i:i+5].upper(),end = "")
#If you want 10 spaces before displaying lenght
print (" "*10 ,end = " ")
print (len(s))
#if you want to reserve 10digits for displaying length replace last two lines with below line
print ("%10d" %(len(s)))
这里有一个简单的方法来获取一个字符串,将它的前5个字母改为大写,并将后面的所有字母改为小写。你不必为此导入任何库。你知道吗
在Python2.7中试试这个
相关问题 更多 >
编程相关推荐