首页 > 编程语言 > 详细

Key words arguments in python function

时间:2019-09-08 16:53:52      阅读:106      评论:0      收藏:0      [点我收藏+]

This is a problem of how to use *args and **kwargs

Just suplement/add a way for defining the default value of arguments that is not assigned in key words when calling the function:

def func(**keywargs):
    if 'my_word' not in keywargs:
        word = 'default_msg'
        print(word)
    else:
        word = keywargs['my_word']
        print(word)

call this by:

func()
func(my_word='love')

you‘ll get:

default_msg
love

read more about *args and **kwargs in python: https://www.digitalocean.com/community/tutorials/how-to-use-args-and-kwargs-in-python-3

Key words arguments in python function

原文:https://www.cnblogs.com/sonictl/p/11486711.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!