2024-05-31 23:39:30 发布
网友
from os import system def a(len1,hgt=len1,til,col=0): system('mode con cols='+len1,'lines='+hgt) system('title',til) system('color',col) a(64,25,"hi","0b") input()
当我运行这个时,它拒绝“def a(…”并突出显示“(”红色)。我不知道为什么。
关键字参数后不能有非关键字参数。
请确保按如下方式重新排列函数参数:
def a(len1,til,hgt=len1,col=0): system('mode con cols='+len1,'lines='+hgt) system('title',til) system('color',col) a(64,"hi",25,"0b")
让我澄清两点:
def example(a, b, c=None, r="w" , d=[], *ae, **ab):
(a,b)是位置参数
(c=无)是可选参数
(r=“w”)是关键字参数
(d=[])是列表参数
(*e)仅为关键字
(*opts)是var关键字参数
所以首先重新安排你的参数
所以第二步删除这个“len1=hgt”在python中是不允许的。
记住参数和参数之间的区别,您可以在这里阅读更多内容:Arguments and parameters in python
如错误消息所示,非默认参数til不应跟随默认参数hgt。
til
hgt
更改参数的顺序(函数调用也会相应地调整)或使hgt成为非默认参数将解决您的问题。
def a(len1, hgt=len1, til, col=0):
->
def a(len1, hgt, til, col=0):
更新
另一个被SyntaxError隐藏的问题。
^{}只接受一个字符串参数。
def a(len1, hgt, til, col=0): system('mode con cols=%s lines=%s' % (len1, hgt)) system('title %s' % til) system('color %s' % col)
关键字参数后不能有非关键字参数。
请确保按如下方式重新排列函数参数:
让我澄清两点:
def example(a, b, c=None, r="w" , d=[], *ae, **ab):
(a,b)是位置参数
(c=无)是可选参数
(r=“w”)是关键字参数
(d=[])是列表参数
(*e)仅为关键字
(*opts)是var关键字参数
所以首先重新安排你的参数
所以第二步删除这个“len1=hgt”在python中是不允许的。
记住参数和参数之间的区别,您可以在这里阅读更多内容:Arguments and parameters in python
如错误消息所示,非默认参数
til
不应跟随默认参数hgt
。更改参数的顺序(函数调用也会相应地调整)或使
hgt
成为非默认参数将解决您的问题。->
更新
另一个被SyntaxError隐藏的问题。
^{} 只接受一个字符串参数。
相关问题 更多 >
编程相关推荐