该代码为每个偶数打印大写的字符串。
我用索引计数器(index=0)检查每个字符的索引。
有没有其他方法可以找到索引?没有肌酸指数?你知道吗
def myfunc(str):
index = 0
low = str.lower()
new_str = ''
for char in str:
if index % 2 == 0:
new_str += char.upper()
else:
new_str += char
index += 1
return new_str
print(myfunc('Hello World'))
Tags:
尝试使用:
输出:
使用Enumerate()方法向iterable添加一个计数器,并以枚举对象的形式返回它。你知道吗
例如
O/p:
相关问题 更多 >
编程相关推荐