python遍历字符串中的字符

2022-03-11 00:00:00 字符串 遍历 字符

python遍历字符串中的字符,python种字符串的遍历类似列表

"""
作者:皮蛋编程(https://www.pidancode.com)
创建日期:2022/3/21
功能描述:python遍历字符串中的字符
"""
word = input("Enter a word: ")
print("\nHere's each letter in your word:")
for letter in word:
    print(letter)

输出结果:
Enter a word: www.pidancode.com

Here's each letter in your word:
w
w
w
.
p
i
d
a
n
c
o
d
e
.
c
o
m

以上代码在Python3.9环境测试通过。

相关文章