Discuss / Python / print() 里面加入字符串为什么就出错了呢?

print() 里面加入字符串为什么就出错了呢?

Topic source

macandle

#1 Created at ... [Delete] [Delete and Lock User]

!/usr/bin/python3

--coding:utf-8 --

L = [ ['Apple','Google','Microsoft'], ['Java','Python','Ruby','PHP'], ['Adam','Bart','Lisa'] ]

print(L[0][0])

print(L[1][1])

print(L[2][2])

上面是我正确的代码!

但是我为了好看,加入了字符串: 如下:

print("我最喜欢吃的水果:"L[0][0])

print("我最喜欢用的语言:"L[1][1])

print("我的女朋友叫什么:"L[2][2])

然后就报错了,为什么呢? File "./my1st.py", line 10 print("我最喜欢吃的水果:"L[0][0]) ^ SyntaxError: invalid syntax

ChuaNZzq

#2 Created at ... [Delete] [Delete and Lock User]

你忘记了加逗号,应该是print("我最喜欢的水果:",L[0][0])

macandle

#3 Created at ... [Delete] [Delete and Lock User]

恩,经过ChuaNZzq的指点,成功了!

我最喜欢吃的水果: Apple 我最喜欢用的语言: Python 我的女朋友叫什么: Lisa

非常感谢!


  • 1

Reply