SyntaxError:解析时出现意外的EOF(Python)

时间:2020-06-23 05:41:11

标签: python string-length

当我尝试打印一个str和len()时,不断收到SyntaxError。请指教

companies = [['Google', 'Facebook', 'Apple'],
            ['Warner Bros. Pictures', '20th Century Fox', 'Universal Pictures'],
            ['Whole foods', 'Starbucks', 'Walmart']]


for x in range(len(companies)):
    for y in range(len(companies[x])):
        print("This company name has length of:" + " " + str(len(companies[x][y]))

1 个答案:

答案 0 :(得分:0)

您只是错过了一个右括号

companies = [['Google', 'Facebook', 'Apple'],
            ['Warner Bros. Pictures', '20th Century Fox', 'Universal Pictures'],
            ['Whole foods', 'Starbucks', 'Walmart']]


for x in range(len(companies)):
    for y in range(len(companies[x])):
        print("This company name has length of:" + " " + str(len(companies[x][y])))