Search code examples
pythonpython-3.xlistfind

Python - Print on screen the letter in position "x"


I need to find and print a letter of a word.

For example: wOrd

I want to print only the uppercase letter. I tried using "find()" it shows me the position of the letter but I can't show the letter "O" it shows "1".

Is it possible to do that?


Solution

  • Using the str.isupper method:

    s = "wOrd"
    
    # print every upper-case character
    print(*(char for char in s if char.isupper()))
    
    # print every upper-case character - functional programming
    print(''.join(filter(str.isupper, s)))
    
    # print the 1st upper-case character. If none returns None
    print(next((char for char in s if char.isupper()), None))