-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstring_functions.py
55 lines (40 loc) · 1.36 KB
/
string_functions.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
47
48
49
50
51
52
53
54
55
# Note-to-self
# you can use pyperclip to copy and paste text to clipboard
# triple quotes to store gigantic text in a string, can print multiline too.
# like: print(""" 400 lines here """)
value = "string"
value_upper = value.upper()
value_lower = value.lower()
if value.isupper():
pass
if value.islower():
pass
# isalpha, isalnum, isdecimal, isspace, istitle
answer = value.startswith("s")
answer2 = value.endswith("g")
join_string = ','.join(['cats', 'cats', 'cancer', 'camel'])
join_str_mod = ' '.join(['cats', 'cats'])
# split method does opposite to join
string = "Hey, whats up, my name is Abraham"
split_list = string.split()
another_str = "Greg, how are you?"
add_leftpad = another_str.ljust(20)
add_rightpad = another_str.rjust(30)
# text would be in center
center_string = another_str.center(20)
# for headings
title = another_str.center(20, '=')
# strip space and ljust, rjust etc
# to remove whitespace from left side = lstrip()
# to remove whitespace from right side = rstrip()
let = "let this be a string, from which we want to remove some chars"
# i would want to remove certain chars from it.
new_let = let.strip('tSwR')
# replace certain char with char or string.
ex = "Jello and Hello"
ex.replace('J', 'H')
ex.replace('l', 'LL')
# p_result: JeLLLLo and heLLLLo
#reverse a string
string_name_here = "something just liek this"
string_name_here[::-1]