-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.txt
More file actions
64 lines (36 loc) · 1.42 KB
/
document.txt
File metadata and controls
64 lines (36 loc) · 1.42 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
String Methods
s.find(substring) --> find the index of the sub string from string string
Strip the strings
strip --> removes the white spaces from both left and right sides
lstrip --> removes the spaces at the begining of String
rstrip --> removes the spaces at the begining of String
count string
s.count(substring) --> counts the occurence of substring in string string
s.count(substring,begin,end) --> from begin index to the end-1 index substring
replace string
s.replace(oldstring,new string) --> replaces old string with new string
eg: s = "Durga sof"
s.replace("sof","soft")
Durga soft
splitting of String:
s.split(separator) --> split the string based on separator
eg:
s = "Durga sof sol"
l = s.split()
print(l) --> ['Durga','sof','sol']
s.rsplit(separator) --> split the string based on separator in reverse
s.split(separator, num) --> splits the string based on separator till the number
join() --> will use to join the separator in the list
eg:
s = ['durga','soft','sol']
l = "-".join(s)
print(l) --> durga-soft-sol
changing case of a strings
upper() ==> to convert to upper case
lower()
swapcase() --> lower to upper and upper to lower case
title() ==> The Python Classes By Durga
capitalize() --> The python classes by durga
Checking starting and ending part of the string
s.startswith('learning') --> check the string starts with substring
s.endswith('learning') --> check the string ends witg substring