python隔一个字符输出如何实现
发布时间:2023-05-17 13:21:00
以下是一种实现方法:
text = "This is a sample text."
for i in range(0, len(text), 2):
print(text[i], end="")
输出结果为:
Ti sasmtet.
注:range(0, len(text), 2) 表示从 0 到 len(text)(不含)之间,以步长为 2 的方式循环遍历。end="" 表示不换行输出。
