2024-05-20 00:38:46 发布
网友
有谁能告诉我为什么在空闲时出现语法错误?在
def printTwice(bruce): print bruce, bruce
语法错误:语法无效
你好像想打印错误。在
可以使用元组:
def p(bruce): print (bruce, bruce) # print((bruce, bruce)) should give a tuple in python 3.x
也可以在Python~2.7中使用字符串格式:
或者使用Python 3中的函数:
def p(bruce): print("{0}{1}".format(bruce, bruce))
检查正在使用的Python版本;变量^{}包含有用的信息。在
这在Python 3.x中是无效的,因为print只是一个普通函数,因此需要括号:
print
# valid Python 3.x syntax .. def x(bruce): print(bruce, bruce) x("chin") # .. but perhaps "cleaner" def x(bruce): print(bruce, bruce)
(Python2.x中的行为是不同的,where ^{} was a special statement。)
你好像想打印错误。在
可以使用元组:
也可以在Python~2.7中使用字符串格式:
^{pr2}$或者使用Python 3中的函数:
检查正在使用的Python版本;变量^{} 包含有用的信息。在
这在Python 3.x中是无效的,因为
print
只是一个普通函数,因此需要括号:(Python2.x中的行为是不同的,where ^{} was a special statement 。)
相关问题 更多 >
编程相关推荐