1. 程式人生 > >Python函式中的預設引數

Python函式中的預設引數

# -*- coding: utf-8 -*-
def hello(greeting='hello', name='world!'):
    print '%s,%s' % (greeting, name)
hello()
hello('I like you')
def hello1(name, greeting='hello', punctuation='!'):
    print '%s, %s%s' % (name, greeting, punctuation)
hello1('world')


當設定函式時如果引數具有預設值,那麼呼叫的時候就可以不用提供引數。