# 带有某些字符串的嵌套循环如何在python中工作？How the nested loop with some string works in python?

``````The website is google number 1
The website is facebook number 2
The website is yahoo number 3
``````

``````websites = "google facebook yahoo"
for web in websites.split( ):
n=0
while n < 3:
n=n+1
print web,n
``````

``````C:\Users\test\Desktop>python nested_loop_in_python.py
yahoo 1
yahoo 2
yahoo 3

C:\Users\test\Desktop>
``````

``````The website is google number 1
The website is facebook number 2
The website is yahoo number 3
``````

## 4 个回复4

### ===============>>#1 票数：2

``````for index, site in enumerate(websites.split(),1):
print(site, index)
``````

### ===============>>#2 票数：1

``````print web,n
``````

``````print ("The website is " + web + " number " + str(n))
``````

``````for web in websites.split():
n=0
while n < 3:
n=n+1
``````

``````n=0
for web in websites.split():
n=n+1
``````

### ===============>>#3 票数：1

``````websites = "google facebook yahoo"
for j, web in enumerate(websites.split(' '), start=1):
print 'The website is {0} number {1}'.format(web, j)
``````

### ===============>>#4 票数：0

``````websites = "google facebook yahoo"

l = websites.split()

for w, i in zip(l, range(len(l))):
print 'The website is {0} number {1}'.format(w,i+1)
``````

``````for w, i in zip(websites.split(), range(len(websites.split()))):
print 'The website is {0} number {1}'.format(w,i+1)
``````