关于Python中的序列类型

2024-07-08 15:41:25 发布

您现在位置:Python中文网/ 问答频道 /正文

#!/usr/bin/python
# -*- coding: utf-8 -*-

# Marcel Iseli
# Python program to manipulate a list 
# by Marcel Iseli

# initialize the variable with a list of words

word1= raw_input()

text = ['Dies', 'ist', 'ein', 'kleiner', 'Text', 'ohne', 'Umlautzeichen', 
    ',', 'der', 'schon', 'in', 'einer', 'Liste', 'gespeichert', 'ist', '.','Er',
    'ist', 'gut', 'geeignet', ',', 'um', 'den',
    'Umgang', 'mit', 'Listen', 'zu', 'verstehen']

# for the list with the name text

for item in text:
    # print the new content of text'

    print 'Bitte enter druecken, um dem Text ein Punkt hinzuzufuegen.'  

    word1 = raw_input()
    text.append('.')
    print text

    print 'Bitte enter druecken, um die Vorkommen vom finiten Verb ist zu zaehlen'

    word1 = raw_input()
    text.count('ist')
    print text

    print 'Bitte enter druecken, um einen weiteren Satz anzufuegen'

    word1 = raw_input()
    text.append('Weils so schoen ist, fuege ich jetzt noch diesen Satz hinzu')
    print text

    print 'Bitte enter druecken, um das Wort gut zu entfernen'

    word1 = raw_input()
    text.remove('gut')  
    print text

    print 'Bitte enter druecken, um das Wort hier einzufuegen.'

    word1 = raw_input()
    text.insert(1, 'hier')
    print text

    print 'Bitte enter druecken, um das Wort dies mit dem Wort das zu ersetzen'

    word1 = raw_input()
    text[0] = 'Das'

    print text

    text.join(text)

    break

我在这里使用的最后一个函数,text.join连接(文本)不起作用。我想显示列表“文本”作为常规文本与它。而且使用时文本.计数,我想显示结果3,但是使用“print text”我无法获得此结果..其他结果在使用“print text”时显示良好。有人能帮我吗?你知道吗


Tags: thetext文本inputrawumprintenter
1条回答
网友
1楼 · 发布于 2024-07-08 15:41:25

.join()str对象的函数,而不是list对象的函数。你知道吗

dir(str)显示了可以对字符串执行的操作,而这个dir(list)显示了可以对列表执行的操作。你知道吗

尝试:

' '.join(text)

这将用分隔符' '连接text的所有对象

相关问题 更多 >

    热门问题