-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringmethods.py
More file actions
61 lines (35 loc) · 1.34 KB
/
Copy pathstringmethods.py
File metadata and controls
61 lines (35 loc) · 1.34 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
46
47
48
49
50
51
52
53
54
55
string = "Sahil Shaikh Mumbai"
#i woudl learn bout strip,split,join, replace, upper/lower, startswith/endswith, find,format
#there are many but acc to claude these are the most useful
print(string.split())
#split returns the words of string in to arrays of words
def scratch_split(argument):
split = []
word = ""
for element in argument:
if element != " ":
word += element
elif element == " ":
split.append(word)
word = ""
l_word = split.append(word)
print(l_word)
return split
print(scratch_split(string))
print(string.strip())
#strip returns the words without any spaces
print("-".join(['a','b','c']))
#joins characters in a string together. is more efficient the concateneting using different varaibles as it hoards up space
print(string.replace("h","e"))
#repllace the characters with the given character in
print(string.upper())
#returns the value of string with all the letters in the string in uppercase
string = "SAHIL"
print(string.lower())
#antonym of upper method of strings
string.startswith("s")
#returns bool to check whether the string starts with the character passed
string.endswith("L")
#returns bool to check whetehr the string ends with the character passed
string.find("e")
#returns the index of teh character passed from teh string.