Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 []:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Update

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

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading