initial project commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
def substring(string: str, start: int, end: int = 0) -> str:
|
||||
"""
|
||||
A substring function
|
||||
:param string: The string
|
||||
:param start: The starting index
|
||||
:param end: The ending index. If None, this is set to the length of the substring :return:
|
||||
"""
|
||||
if not isinstance(string, str):
|
||||
raise ValueError("No string provided")
|
||||
if not isinstance(start, int):
|
||||
raise ValueError("No starting index provided")
|
||||
|
||||
if end is None:
|
||||
end = len(str)
|
||||
|
||||
result = ""
|
||||
|
||||
for i in range(start, end):
|
||||
result += string[i]
|
||||
|
||||
return result
|
||||
Reference in New Issue
Block a user