-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay12.py
More file actions
106 lines (68 loc) · 2.15 KB
/
Day12.py
File metadata and controls
106 lines (68 loc) · 2.15 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# String methods
a = "!! Light!! !!"
print(len(a))
# Upper() and Lower()
# string are immutable, however we create a new copy of string to make changes
print("\nUpper() and Lower() example: ")
print(a.upper())
print(a.lower())
# rstrip()
# Removes any trailing characters
print("\nrstrip() example: ")
print(a.rstrip("!"))
# replace()
# Replaces all occurrences of a string with another string
print("\nreplace() example: ")
print(a.replace("Light", "Dark"))
# Split()
# Splits the given string at the specified instances and returns the seprarated strings as "list" items
print("\nSplit() example: ")
print(a.split(" "))
# Capitalize()
# turns only the first character of the string to uppercase and the rest other characters of string are turned to lowercase.
# The string has no effect if the first character is already uppercase
print("\nCapitalize() example: ")
b = "introduction to python"
c = "\ninTroducTion to pytTon"
print(b.capitalize())
print(c.capitalize())
# center()
# aligns the string to the center as per parameters
print("\ncenter() example: ")
print(b.center(50))
print(len(b.center(50)))
print(len(b.center(1)))
# Count()
print("\nCount() example: ")
d = "Dark"
print(d.count("\nDark"))
# Endswith()
print("\nEndswith() example: ")
print(a.endswith("!!"))
print(a.endswith("ht", 4, 7))
# find()
# searches for the first occurrence of the given value and returns the index where it is present.
# If the given value is absent form the string then return -1
print("\nFind() example: ")
print(b.find("to"))
# Index()
# It searches for the first occurrence of the given value and return the index where it is present.
# if given value is absent form the string then raise an exception.
print("\nIndex() example: ")
print(b.index("to"))
# print(b.index("Myy"))
# isalnum()
# returns True only if the entire string only consists of A-Z, a-z,0-9,
# If any other character or punctuation are present, then it returns false.
print("\nisalnum() example: ")
e = "WelcomeToPython"
f = "WelcomeTo100DaysOfPython"
print(e)
print(e.isalnum())
print(f)
print(f.isalnum())
# isalpha()
# A-Z and a-z
print("\nisalpha() example: ")
print(f)
print(f.isalpha())