+ 2

How can I print a Python set so it looks clean (no {} brackets or quotes)?

Hey! I’m working with a set in Python like this: >> fruits = {"apple", "banana", "mango"} However, whenever I print it, curly brackets and quotes appear around the words. I want the output to look like this (just plain words): apple banana mango What’s the simplest way to do this? (Bonus: What if my set contains numbers instead of strings?)

29th Jul 2025, 6:42 PM
SAIFULLAHI KHAMISU
SAIFULLAHI KHAMISU - avatar
2 Respostas
+ 3
Use the unpacking operator: print(*fruits) What output do you want to achieve for numbers?
29th Jul 2025, 7:28 PM
Lisa
Lisa - avatar
0
You can use "join". fruits = sorted(fruits, key=None, reverse=False) fruits = ' '.join(fruits) print(fruits) https://www.sololearn.com/ru/compiler-playground/cmmPWZygqs4i/?ref=app
29th Jul 2025, 7:31 PM
Mila
Mila - avatar