-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7-Strings Methods Part 2.py
More file actions
52 lines (36 loc) · 921 Bytes
/
7-Strings Methods Part 2.py
File metadata and controls
52 lines (36 loc) · 921 Bytes
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
# ---------------------
# -- Strings Methods --
# ---------------------
# split() rsplit()
a = "I Love Python and PHP and MySQL"
print(a.split())
b = "I-Love-Python-and-PHP-and-MySQL"
print(b.split("-"))
c = "I-Love-Python-and-PHP-and-MySQL"
print(c.split("-", 3))
d = "I-Love-Python-and-PHP-and-MySQL"
print(d.rsplit("-", 3))
# center()
e = "Osama"
print(e.center(9)) # Spaces
print(e.center(9, "#")) # Hashes
print(e.center(15, "@")) # @
# count()
f = "I Love Python and PHP Because PHP is Easy"
print(f.count("PHP")) # 2 PHP Words
print(f.count("PHP", 0, 25)) # Only One PHP Word
# swapcase()
g = "I Love Python"
h = "i lOVE pYTHON"
print(g.swapcase())
print(h.swapcase())
# startswith()
i = "I Love Python"
print(i.startswith("I"))
print(i.startswith("S"))
print(i.startswith("P", 7, 12))
# endswith()
j = "I Love Python"
print(j.endswith("n"))
print(j.endswith("S"))
print(j.endswith("e", 2, 6))