forked from chavarera/PythonScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.StringMethods.py
More file actions
52 lines (35 loc) · 997 Bytes
/
2.StringMethods.py
File metadata and controls
52 lines (35 loc) · 997 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
#Following are the some string methods
##1.Split
#if you want to devide a string with white space or commas or some special charcter then split method is used
mystring="india pakistan china america"
#split a string with whitespaces
splitstring=mystring.split(' ')
print(splitstring)
##['india', 'pakistan', 'china', 'america']
##if you want to split that string and store it in different variable
a,b,c,d=mystring.split(' ')
print(a)
print(b)
print(c)
print(d)
##india
##pakistan
##china
##america
##2.join
mylist=['india', 'pakistan', 'china', 'america']
strings=','.join(mylist)
print(strings)
##india,pakistan,china,america
##3.count
lis=[3,5,54,3,3,3,4,5,56,66,3,3,3,23,4,6,6,77,34,345,67,6,78]
#if you want to count how much times the 3 appears in list
print(lis.count(3))
##7
##4.Replace
stat='kat is good girl'
##if you want to replace is with was then replace is used
#replace('old word','new word')
newstring=stat.replace('is','was')
print(newstring)
##kat was good girl