Last active
November 20, 2019 21:08
-
-
Save les-peters/50cad91305d08a0fff209788cdc27e68 to your computer and use it in GitHub Desktop.
cassidoo-1118.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mySubstring(w, *a): | |
O = "" | |
C = [char for char in w] | |
for i in range(len(C)): | |
if len(a) == 1: | |
O += C[i] if i >= a[0] else '' | |
else: | |
O += C[i] if i >= a[0] and i < (a[0]+a[1]) else '' | |
print(O) | |
class X(str): | |
def mySubstring(self, *a): | |
O = "" | |
C = [char for char in self] | |
for i in range(len(C)): | |
if len(a) == 1: | |
O += C[i] if i >= a[0] else '' | |
else: | |
O += C[i] if i >= a[0] and i < (a[0]+a[1]) else '' | |
print(O) | |
# simple function | |
a = 'hello world!' | |
mySubstring(a,1,5) | |
mySubstring(a,6) | |
# class extension, more in tune with the ask | |
s = X("hello world!") | |
s.mySubstring(1,5) | |
s.mySubstring(6) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment