String Methods
Python has a set of built-in methods that you can use on strings.
Note: All string methods returns new values. They do not change the original string.
For example, the upper() method returns a string where all characters are in upper case.
# example string string = "this should be uppercase!" print(string.upper()) # string with numbers # all alphabets whould be lowercase string = "Th!s Sh0uLd B3 uPp3rCas3!" print(string.upper())
Results:
>>> THIS SHOULD BE UPPERCASE! TH!S SH0ULD B3 UPP3RCAS3!
![](https://static.wixstatic.com/media/d400f8_dc77ddfa62e24ab5ac06f323aab8c0ee~mv2.jpg/v1/fill/w_506,h_463,al_c,q_80,enc_auto/d400f8_dc77ddfa62e24ab5ac06f323aab8c0ee~mv2.jpg)
My code:
userWord = input("Enter a word: ") # Prompt the user to enter a word userWord = userWord.upper() # and assign it to the userWord variable. for letter in userWord: if letter == "A": continue elif letter == "E": continue elif letter == "I": continue elif letter == "O": continue elif letter == "U": continue print(letter.upper())
#############or just print(letter)
![](https://static.wixstatic.com/media/d400f8_d9908d7b3d1049dc9378be96b036957e~mv2.jpg/v1/fill/w_508,h_503,al_c,q_80,enc_auto/d400f8_d9908d7b3d1049dc9378be96b036957e~mv2.jpg)
My code:
wordWithoutVovels = "" userWord = input("Enter a word: ") userWord = userWord.upper() for letter in userWord: if letter == "A": continue elif letter == "E": continue elif letter == "I": continue elif letter == "O": continue elif letter == "U": continue wordWithoutVovels += letter else: print(wordWithoutVovels)
Test data
Sample input: Gregory
Expected output: GRGRY
Sample input: abstemious
Expected output: BSTMS
Sample input: IOUEA
Expected output is empty
References: