Give the parameters in the function default values : Function Default Argument « Function « Python






Give the parameters in the function default values

Give the parameters in the function default values
def hello_3(greeting='Hello', name='world'):
    print '%s, %s!' % (greeting, name)

hello_3()

hello_3('Greetings')

hello_3('Greetings', 'universe')

hello_3(name='Gumby')


def hello_4(name, greeting='Hello', punctuation='!'):
    print '%s, %s%s' % (greeting, name, punctuation)


hello_4('Mars')

hello_4('Mars', 'Hi')

hello_4('Mars', 'Hi', '...')

hello_4('Mars', punctuation='.')

hello_4('Mars', greeting='It is a greeting!')

           
       








Related examples in the same category

1.Default parameter of a function is 'global'Default parameter of a function is 'global'
2.Make default not globalMake default not global
3.Check if a default parameter value being usedCheck if a default parameter value being used
4.keyword argumentskeyword arguments
5.Default parameter valuesDefault parameter values
6.Default Argument Values: a simple demoDefault Argument Values: a simple demo
7.Default Argument Values: default values are evaluated at the point of function definitionDefault Argument Values: default values are evaluated at the point of function definition
8.Default Argument Values: default value is evaluated only onceDefault Argument Values: default value is evaluated only once
9.Default Argument Values: If you don't want the default to be shared between subsequent calls