How can I print a list that doesn't have the default [] and is changed to capital letters?

I have a list in python e.g.

letters = ["a", "b", "e"]

And I can print it without the default []:

print(', '.join(letters))

a, b, e

But how can I print out A, B, E so that the strings in the list are all uppercase?

I tried doing print(', '.join(letters).upper) but that didn’t work.

>Solution :

You need to apply .upper() to each string in your list:

alist = ["a", "b", "e"]
print(', '.join([c.upper() for c in alist]))

Output as requested.


Alternatively, since .join() produces a string, then .upper() will work on that:

print(', '.join(alist).upper())

Leave a Reply