Python程序:打印字符串中的字符

创新互联Python教程:

写一个 Python 程序来打印字符串中的字符,并给出一个实例。

打印字符串中的字符的 Python 程序示例 1

这个 python 程序允许用户输入一个字符串。接下来,它使用 For 循环打印该字符串中的字符。这里,我们使用 For 循环来迭代字符串中的每个字符。在 Python For 循环中,我们使用 print 语句打印该字符串中的字符。

提示:请参考字符串文章,了解 Python 中关于字符串的一切。

# Python program to Print Characters in a String

str1 = input("Please Enter your Own String : ")

for i in range(len(str1)):
    print("The Character at %d Index Position = %c" %(i, str1[i]))

返回字符串中的字符的 Python 程序示例 2

这个 python 程序显示字符串中的字符同上。然而,我们只是将换成了同时换成了。

# Python program to Print Characters in a String

str1 = input("Please Enter your Own String : ")
i = 0

while(i < len(str1)):
    print("The Character at %d Index Position = %c" %(i, str1[i]))
    i = i + 1

Python 打印字符串输出

Please Enter your Own String : Tutorial Gateway
The Character at 0 Index Position = T
The Character at 1 Index Position = u
The Character at 2 Index Position = t
The Character at 3 Index Position = o
The Character at 4 Index Position = r
The Character at 5 Index Position = i
The Character at 6 Index Position = a
The Character at 7 Index Position = l
The Character at 8 Index Position =  
The Character at 9 Index Position = G
The Character at 10 Index Position = a
The Character at 11 Index Position = t
The Character at 12 Index Position = e
The Character at 13 Index Position = w
The Character at 14 Index Position = a
The Character at 15 Index Position = y

文章题目:Python程序:打印字符串中的字符
转载来于:http://www.hxwzsj.com/article/cddsphi.html

其他资讯

Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14
友情链接: 网站设计制作 企业手机网站建设 四川成都网站建设 网站制作 成都营销网站制作 网站制作 营销型网站建设 手机网站建设套餐 成都网站制作 成都网站建设 上市集团网站建设 成都网站建设 温江网站设计 重庆网站制作 盐亭网站设计 网站建设 成都网站建设推广 成都网站制作 网站建设 网站设计 成都定制网站建设 重庆网站建设