首页题目详情

在 Python 中,以下哪个语句可以遍历字符串 'Python' 的每个字符?

题目配图
A.for ch in 'Python': print(ch)
B.for ch in range(6): print(ch)
C.for ch in list('Python'): print(ch)
D.for ch in tuple('Python'): print(ch)

优质解答

答案

A

解析

字符串在 Python 中是可迭代对象,所以可以直接用 for 循环遍历。选项 A 是最直接的方式。

查看答案和解析

支付 ¥0.1 即可查看此题答案和详细解析

低至 ¥0.1 起

Python程序设计单选题中等AI生成