Python 默认参数 关键词参数 位置参数

def StudentInfo(country='中国', name):

    print('%s,%s' % (name, country))


StudentInfo('美国', '大卫')

上述代码报错:

原因:SyntaxError: non-default argument follows default argument

def StudentInfo(country='中国', name):

^

def StudentInfo(name, chineselevel='良好', country='中国'):
    print('姓名:%s,中文水平:%s,国家:%s'%(name,chineselevel,country))
StudentInfo(name='大卫', '良好', '美国')

上述代码报错:

原因:SyntaxError: positional argument follows keyword argument

StudentInfo(name='大卫', '良好', '美国')

^

posted @ 2019-06-01 16:47  喵喵小学僧  阅读(391)  评论(0编辑  收藏  举报