在Python中,你可以使用for
循环遍历字符串中的每个字符并输出。这里有一个例子:
string = "Hello, World!"
for char in string:
print(char)
这段代码将会逐个输出字符串"Hello, World!"中的每个字符。每个字符都会单独输出一行。如果你想要在同一行输出所有字符,可以将print(char)
改为print(char, end='')
。这样,end=''
参数会让每次输出后不换行。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:python怎么循环输出字符串