String Methods Flashcards
(12 cards)
What does len stand for?
Length, like the length of your name can be found by the following:
name= “Meeko”
print(len(name))
TWD: 5
This is the length method for str methods
How do you find a character within a str?
name= “Meeko”
print(name.find(“e”))
TWD 1
M=0 e=1 e=2 k=3 o=4
How do you capitalize?
name=”meeko”
print(name.capitalize())
TWD Meeko
How do you uppercase?
name=”meeko”
print(name.upper())
TWD: MEEKO
How do you lowercase?
name=”Meeko”
print(name.lower())
TWD: meeko
How do you find if something is a digit?
name=123
print(name.isdigit())
TWD: True
Isalpha?
Are these alphabetical characters. Cannot have any spaces if you want it to be true (only has letters)
name=”meeko”
print(name.isalpha())
TWD: True
What is the count str method used for?
Count is used to count how many characters are within your str
name=”Meeko”
print(name.count())
TWD: 5
Write a code to count how many S’s are in Mississippi
name=”Mississippi”
print(name.count(“s”))
TWD: 4
Write a code to count how many S’s are in Mississippi
name=”Mississippi”
print(name.count(“s”))
TWD: 4
Write a code that replaces all the of S’s to T’s in Mississippi
name=”Mississippi”
print(name.replace(“s”,”t”))
TWD: Mittittippi
Create a code that will repeat duck 5xs
name=”duck