-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_methods.py
More file actions
45 lines (29 loc) · 1.01 KB
/
string_methods.py
File metadata and controls
45 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
string_ethods.py
"""
def capitalize_title(title):
"""
:param title: str title string that needs title casing
:return: str title string in title case (first letters capitalized)
"""
return title.title()
def check_sentence_ending(sentence):
"""
:param sentence: str a sentence to check.
:return: bool True if punctuated correctly with period, False otherwise.
"""
return sentence.endswith('.')
def clean_up_spacing(sentence):
"""
:param sentence: str a sentence to clean of leading and trailing space characters.
:return: str a sentence that has been cleaned of leading and trailing space characters.
"""
return sentence.strip()
def replace_word_choice(sentence, old_word, new_word):
"""
:param sentence: str a sentence to replace words in.
:param old_word: str word to replace
:param new_word: str replacement word
:return: str input sentence with new words in place of old words
"""
return sentence.replace(old_word, new_word)