小编Tra*_*sta的帖子

Python **kwargs 中的 KeyError

只有第一个打印命令有效。我不明白为什么。我想根据传入的内容显示不同的前缀和后缀。

# We are going to have a word and a prefix or a suffix before or after
# that word

def joinWords(string, **sFox):
    if sFox['prefix']: 
        return sFox['prefix'] + string
    elif sFox['suffix']: 
        return string + sFox['suffix']
    return string




#Why does this work?
#print(joinWords("Cookie", prefix="sugar"))

#And this does not?
#print(joinWords("Cookie", suffix="monster"))
Run Code Online (Sandbox Code Playgroud)

python python-3.x

2
推荐指数
1
解决办法
6732
查看次数

标签 统计

python ×1

python-3.x ×1