Codewars 8 kyu Exclamation marks series #2: Remove all exclamation marks from the end of sentence
Task
Remove all exclamation marks from the end of sentence.
Verbalization
- 最後の文字が!である限り、
- 最後の文字を消す
Code
def remove(st):
while st.endswith("!"):
st = st[:-1]
return st
Other example
rstrip = remove all exclamation marks from the end of the string
def remove(st):
return st.rstrip(“!”)
Reference
もし、!をすべてけしたかったら、
- for文で1つづつ文字をとりだす
- もし!でなければ、
- 文字をつなげる
def remove(st):
words = ""
for i in st:
if i != "!":
words += i
return words