**Kwargs 中的输出格式
Output format in **Kwargs
我想将我的输出格式化为-
我选择的水果是苹果鳄梨。但不确定它是否正确执行,也许我在格式化时遗漏了一些东西。你能告诉我哪里做错了吗?
#Kwargs
def my_func(**kwargs):
print(kwargs)
if 'fruit' 'veggie' in kwargs:
print('My choice of fruits are {} {}'.format(kwargs['fruit'],['veggie']))
else:
print('Sorry we can not find your fruit here!')
my_func(fruit='apple', veggie= 'Avocado')
以上代码段的输出为-
{'fruit': 'apple', 'veggie': 'Avocado'}
抱歉,我们在这里找不到您的水果!
'fruit' 'veggie' == 'fruitveggie'
['veggie']
是 list
的 str
- 了解 f 弦
所以,
def my_func(**kwargs):
print(kwargs)
if 'fruit' in kwargs and 'veggie' in kwargs:
print(f'My choice of fruits are {kwargs["fruit"]} {kwargs["veggie"]}')
else:
print('Sorry we can not find your fruit here!')
my_func(fruit='apple', veggie='Avocado')
我想将我的输出格式化为- 我选择的水果是苹果鳄梨。但不确定它是否正确执行,也许我在格式化时遗漏了一些东西。你能告诉我哪里做错了吗?
#Kwargs
def my_func(**kwargs):
print(kwargs)
if 'fruit' 'veggie' in kwargs:
print('My choice of fruits are {} {}'.format(kwargs['fruit'],['veggie']))
else:
print('Sorry we can not find your fruit here!')
my_func(fruit='apple', veggie= 'Avocado')
以上代码段的输出为- {'fruit': 'apple', 'veggie': 'Avocado'} 抱歉,我们在这里找不到您的水果!
'fruit' 'veggie' == 'fruitveggie'
['veggie']
是list
的str
- 了解 f 弦
所以,
def my_func(**kwargs):
print(kwargs)
if 'fruit' in kwargs and 'veggie' in kwargs:
print(f'My choice of fruits are {kwargs["fruit"]} {kwargs["veggie"]}')
else:
print('Sorry we can not find your fruit here!')
my_func(fruit='apple', veggie='Avocado')