+ 2
When I am running this code,this code give me error. Please tell me why? I am confused now.😓
def show_item(categories,*items): print("categories:"+items) for item in items: print(item) show_item("monitor","mobile","television")
8 ответов
+ 8
In future, please link to your code in the playground. By pasting in the question, you may introduce new errors. You may even disguise errors which we can only guess.
For the given code there are indentation errors. Lines 3 and 4 are currently outside of the method body. Also, you cannot concatenate a string with a tuple. Perhaps, you want a string representation of the tuple:
print("categories:" + str(items))
+ 4
Amitesh Yadav ,
besides the already mentioned issues, some questions raise up for me:
> since you did not provide an input / output sample or a task description, the purpose of your code is not quite clear.
> you pass 3 string items when calling the function `show_item()`. the function has 2 parameters to store the 3 items:
`categories` -> a string: 'monitor'
`items` -> a tuple of strings: ('mobile', 'television')
why is this done this way? we can just use *one* data container to take all of the items passed by the caller.
using: def show_item(*items): will result in: -> tuple of strings: ('monitor', 'mobile', 'television')
now you can do whatever you like with the items...
+ 3
Thanks bro. It help me a lot ☺️😊😊
+ 3
def show_item(category, *items):
print("Category:", category)
for item in items:
print(item)
show_item("Electronics", "monitor", "mobile", "television")
+ 1
You're welcome :)
+ 1
Father Cubans cost they adding furniture and Pro
0
With anime gaining popularity worldwide, there is an increasing need for localized content that resonates with diverse cultural contexts. The AI anime generator tool can be used to create characters, environments, and narratives tailored to specific regions or cultures. For example, creators can produce anime that reflects local folklore, societal themes, or cultural aesthetics, ensuring that content is both globally appealing and locally relevant. This localization capability enhances cross-cultural understanding and appreciation while also providing a more personalized experience for global audience s https://airbrush.com/ru/ai-anime-generator .
0
Here is right !!!
def show_item(categories, *items):
print("categories:", items)
for item in items:
print(item)
show_item("monitor", "mobile", "television")
Come to see my pikachu!!!!
https://tutodessiner.fr/dessin-pikachu-facile/