美文网首页
python 关键字参数

python 关键字参数

作者: 橙姜 | 来源:发表于2018-02-06 10:06 被阅读0次

    def person(name,age,**kw):
    print('name:',name,'age:',age,'other:',kw)
    person('Frank','37')
    person('Frank','37',city='Shanghai')
    person('Frank','37',gender='M',job='Engineer')


    ('name:', 'Frank', 'age:', '37', 'other:', {})
    ('name:', 'Frank', 'age:', '37', 'other:', {'city': 'Shanghai'})
    ('name:', 'Frank', 'age:', '37', 'other:', {'gender': 'M', 'job': 'Engineer'})

    def enroll(*args, age=6, city='Beijing'):
    print args
    print 'age :',age
    print 'city :',city
    enroll("xiaoming", "male")


    File "2.py", line 1
    def enroll(*args, age=6, city='Beijing'):
    ^
    SyntaxError: invalid syntax

    def enroll(name, sex, age=6, city='Beijing'):
    print name
    print sex
    print 'age :',age
    print 'city :',city
    enroll("xiaoming", "male")


    xiaoming
    male
    age : 6
    city : Beijing

    相关文章

      网友评论

          本文标题:python 关键字参数

          本文链接:https://www.haomeiwen.com/subject/wvowzxtx.html