-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathexercise6.py
36 lines (28 loc) · 1.12 KB
/
exercise6.py
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
""" Output formatting
Write a python class for string processing. It should have the following functions:
- Return a string's lowercase
- Return a string's uppercase
- Format print two strings by using key
- Change a camel-cased word like "WordVector" to "word_vector".
Hints:
- Use `re.sub()` for camel-case conversion
- Read [the Regular Expression Operations](https://docs.python.org/3/library/re.html)
"""
import re
class Str_process:
def lowercase_string(self, string):
return string.lower()
def uppercase_string(self, string):
return string.upper()
def format_print(self, string1, string2):
print('String1: {one}; String2: {two}.'.format(one=string1, two=string2))
return
def camel_string(self, string):
"""Splits a CamelCased string into a new one, capitalized, where words are separated by blanks."""
s1 = re.sub('(.)([A-Z])', r'\1_\2', string)
return s1.lower()
x = Str_process()
print(x.lowercase_string("MY"))
print(x.uppercase_string("sfhkds"))
x.format_print("a", "b")
print(x.camel_string("WordCatVector"))