Discuss / Python / 命名关键字参数报错

命名关键字参数报错

Topic source

def person(name, age, *, city, job): print person(name, age, city, job) person('Jack',24,city='Beijing',job='Engineer')

练习到命名关键字参数,提示位置语法错误,这是为什么呢?位置应该没有错啊 我用的是python2.7.11 File "C:\Users\Richie\OneDrive\python\first.py", line 1 def person(name, age, , city, job): ^

贴上来有问题,重贴下: File "C:\Users\Richie\OneDrive\python\first.py", line 1 def person(name, age, *, city, job): ^ SyntaxError: invalid syntax

语法错误 指向的是 星号 * 直接把文章里的代码贴进去,也是一样的错误。很奇怪。 难道不能这么用吗?

廖雪峰

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

命名关键字是python 3以后才加进入的,2.x不支持


  • 1

Reply