top of page

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!

 
 

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)

 
 

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:

bottom of page