在Python中将字符串添加到列表中

时间:2018-11-27 16:03:39

标签: python python-3.x

我正在尝试在功能中列出一个列表,并在用户编写国家/地区后打印“新”列表。

def main():
    while True:
        user()
        my_list()


def my_list():
    c = ["England", "Japan", "China"]
    print(c)

def user():
    country = input("Country?")
    new = my_list().append(country)
    return new

main()

但是此代码出现错误。 我感谢所有帮助。

1 个答案:

答案 0 :(得分:0)

尝试一下:

def main():
    c = []
    while True:
        country = input("Country?")
        c.append(country)
        for i in c:
            print(i)
main()