我不知道为什么我的代码会继续出错

时间:2016-03-06 00:07:00

标签: python

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

我该如何解决?

1 个答案:

答案 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)