使用 while 循环从字符串中一次打印一个字符 [英] Printing one character at a time from a string, using the while loop

查看:75
本文介绍了使用 while 循环从字符串中一次打印一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读Core Python Programming 2nd Edition",他们要求我使用while"循环打印一个字符串,一次一个字符.

Im reading "Core Python Programming 2nd Edition", They ask me to print a string, one character at a time using a "while" loop.

我知道 while 循环是如何工作的,但由于某种原因,我无法想出如何做到这一点.我一直在环顾四周,只看到使用 for 循环的示例.

I know how the while loop works, but for some reason i can not come up with an idea how to do this. I've been looking around, and only see examples using for loops.

所以我必须做的:

用户提供输入:

text = raw_input("Give some input:  ")

我知道如何从数组中读出每条数据,但我不记得如何对字符串执行此操作.

I know how to read out each piece of data from an array, but i can't remember anything how to do it to a string.

现在我需要做的就是工作 while 循环,它打印字符串的每个字符,一次一个.

Now all i need is working while-loop, that prints every character of the string, one at a time.

我想我必须使用 len(text),但我不是 100% 确定如何在这个问题中使用它.

i guess i've to use len(text), but i'm not 100% sure how to use it in this problem.

一些帮助会很棒!我确定这是一个非常简单的问题,但由于某种原因我无法想出它!

Some help would be awsome! I'm sure this is a very simple issue, but for some reason i cannot come up with it!

提前谢谢!:)

推荐答案

我很确定,互联网上到处都是 Python 的 while 循环,但举个例子:

I'm quite sure, that the internet is full of python while-loops, but one example:

i=0

while i < len(text):
    print text[i]
    i += 1

这篇关于使用 while 循环从字符串中一次打印一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆