-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10StringsMethods.py
64 lines (44 loc) · 1.13 KB
/
10StringsMethods.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
56
57
58
59
60
61
62
63
64
# Capitalize String
text = "the text goes like this."
print(text) #normal
x = text.capitalize()
print(x)
# ********************
# Covert to UPPERCASE
y = text.upper()
print(y)
# Convert to lowercase
text1 = "THe text1 GoEs LiKe ThIs."
print(text1.lower())
# or
a = text1.lower()
print(a)
# ********************
# Get Length of a String
print("length of the string is" , len(text))
# ********************
#Remove Whitespace
a = " Hello, World! "
print(a.strip()) # returns "Hello, World!"
# *********************
# Replacing Parts of String >> string.replace(old substring, new substring)
b = text.replace("text" , "string")
print(b)
text2 = "Hello World! I love World! World is amazing!"
print(text2)
c = text2.replace("World", "Everyone")
print(c)
d = text2.replace("World", "Everyone", 2)
print(d)
# *********************
# Split String
a = "Hello, World!"
print(a.split(",")) # returns ['Hello', ' World!']
# **********************
# Checking Presence of Value on a String
m = "goes" in text
print(m)
n = "nope" in text
print(n)
o = "nope" not in text
print(o)