【发布时间】:2012-01-03 07:07:03
【问题描述】:
index = [0, 2, 5]
s = "I am like stackoverflow-python"
for i in index:
s = s[i].upper()
print(s)
IndexError: string index out of range
我知道在第一次迭代中,字符串s 只是第一个字符,在这种特殊情况下是大写的“I”。但是,我尝试在没有 "s = " 的情况下使用 swapchcase() 来代替,但它不起作用。
基本上,我正在尝试使用 Python 3.X 打印带有索引字母为大写的 s 字符串
【问题讨论】:
标签: python string python-3.x uppercase