-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringMethod.py
48 lines (31 loc) · 1.17 KB
/
stringMethod.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
37
38
39
40
41
42
43
44
45
46
#upper and lower
spam = 'hello world'
spam.upper()
spam.upper()
spam.isupper() #bool
spam.islower() #bool
#needs letters
#chanining
spam.upper().isupper()
spam.isupper() #letters only
spam.islnum() #letters and numbers only
spam.isdecimal() #numbers only
spam.isspace() #whitespace only
spam.istitle() #titlecase only first letter is capital, other is lowercase
spam.title() # turns to title
spam.startswith('i') #can be a longer string
spam.endswith('q') #can be a longer case
','.join(['h', 'e', 'l', 'l', 'o']) #what is joining the array (list together)
'my name is isaq'.split() #end of string to turn into array, default is space
'my name is ishaq'.splt('m') #spilts on m
'ishaq'.rjust(10) #total length is 10 .. white space pads to the right
'ishaq'.ljust(10) # same but padding on left
'ishaq'.rjust(10, '8') #padding is 8
'ishaq'.center(10, '*') #centers it
' ishaq '.strip() # removes white space
' sihaq '.lstrip() # left side remove
' isjahkh '.rstrip() #right side
thing = '123ishaq123'.strip('123') #removes the characters passed into the argument
print(thing)
'111111hello'.replace('111', '!') #replaces first strng with second parameter
#pyperclip