def square(10):
"""returns the square of a number"""
squared = 10**2
print "%d squared is %d." % (10, squared)
return squared
一直在说
File "python", line 1
def square(10):
^
SyntaxError: invalid syntax
我该如何解决?
答案 0 :(得分:0)
您使用了文字10
,您应该使用参数名称。看到:
http://www.tutorialspoint.com/python/python_functions.htm
你真正想要的基本上是:
def square(x):
"""returns the square of a number"""
squared = x**2
print "%d squared is %d." % (10, squared)
return squared
square(10)