Python2.7-不使用新行进行循环打印

Python2.7-不使用新行进行循环打印,python,python-2.7,for-loop,newline,Python,Python 2.7,For Loop,Newline,我在主图像列表中得到两个项目,只想打印第一个。我尝试在findall行之后添加[0],但是它会垂直打印每个字母。我想这是因为for循环将所有内容打印在一行上,但我无法使其全部打印在一行上 # Extract the first image (this is always the main image) that is in the # "LIMITED" category main_watch_images = findall('<img.* src="([^"]+).*LIMITED"'

我在主图像列表中得到两个项目,只想打印第一个。我尝试在findall行之后添加[0],但是它会垂直打印每个字母。我想这是因为for循环将所有内容打印在一行上,但我无法使其全部打印在一行上

# Extract the first image (this is always the main image) that is in the
# "LIMITED" category
main_watch_images = findall('<img.* src="([^"]+).*LIMITED"', dennisov_html)
# Convert the URL to a full address
for images in main_watch_images:
    if images.startswith('/'):
        images = 'https://denissov.ru' + images 
    print images
#提取图像中的第一个图像(这始终是主图像)
#“有限”类别
main\u watch\u images=findall('
请注意,这与其他问题不同。我是一个绝对的初学者,无法理解其他答案中使用的技术和运算符等。我需要一个具体的问题答案

我在主图片列表中得到了两个项目,我只想 打印第一张

您可能正在寻找
break

# Extract the first image (this is always the main image) that is in the
# "LIMITED" category
main_watch_images = findall('<img.* src="([^"]+).*LIMITED"', dennisov_html)
# Convert the URL to a full address
for images in main_watch_images:
    if images.startswith('/'):
        images = 'https://denissov.ru' + images
        print images
        break
    print images
我在主图片列表中得到了两个项目,我只想 打印第一张

您可能正在寻找
break

# Extract the first image (this is always the main image) that is in the
# "LIMITED" category
main_watch_images = findall('<img.* src="([^"]+).*LIMITED"', dennisov_html)
# Convert the URL to a full address
for images in main_watch_images:
    if images.startswith('/'):
        images = 'https://denissov.ru' + images
        print images
        break
    print images

findall()
返回什么?您是否可以显示一个示例输出?可能的重复项,如副本上的一个答案所示,使用
打印图像,
(注意
)。它提供了两个网站,就像这样,我只想打印列表中名为main\u watch\u images的第一项来打印第一个网站。如果我使用[0]在这一行上,它会垂直打印每一个字母。什么是
findall()。它提供了两个网站,就像这样。我只想通过打印列表中名为main_watch_images的第一项来打印第一个网站。如果我使用[0]在这一行上,它垂直打印每个字母是的,在这个实例中有效,但是可能有一个实例,我想打印第二个字母,所以希望按它们所在的位置打印列表中的项目,即[0],[1]然后在做其他事情之前,您可能应该将这些“图像”存储在一个集合中,即
list
image\u list.append('https://denissov.ru“+图像)
然后您只需执行
打印图像列表[0]
是的,主要的\u watch\u图像是一个列表……但是我需要其中的if语句将域添加到缺少它的图像中,并且我知道如何使用if语句的唯一方法是for循环。谢谢。老实说,我已经研究这个问题太久了,已经忘记了为什么我需要在中显示链接首先。在我重新评估我需要做的事情后,我会很快再回来。我会建议你创建一个新的问题,以免混淆其他人。如果这个答案满足你当前的问题,请接受它作为结束问题的答案。啊,是的,在这种情况下有效,但是可能有一个我想优先考虑的问题nt第二个用户希望按项目所在位置打印列表中的项目,即[0]、[1]等。然后,在执行其他操作之前,您可能应该将这些“图像”存储在集合中,即
list
image\u list.append('https://denissov.ru“+图像)
然后您只需执行
打印图像列表[0]
是的,主要的\u watch\u图像是一个列表……但是我需要其中的if语句将域添加到缺少它的图像中,并且我知道如何使用if语句的唯一方法是for循环。谢谢。老实说,我已经研究这个问题太久了,已经忘记了为什么我需要在中显示链接首先,在我重新评估我需要做的事情后,我会很快回到这个问题上来。我建议你创建一个新问题,以免混淆其他人。如果这个答案满足你当前的问题,请接受它作为结束问题的答案。