# Python: String's Method
- In this lesson, we will learn about what we can do on
string.
# in
a = "HelloWorld"
print("Hello" in a)
print("he" in a)
1
2
3
2
3
OUTPUT
True
False
# split
returnthelistofstringwhich are splited.
a = " Hello 1 2 3 5 6 7 9 10 0"
print(a.split())
b = "Hello,1,2,3,5,9"
print(b.split(","))
c = "1-2-3-4-5-6 -7"
print(c.split("-"))
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
OUTPUT
['Hello', '1', '2', '3', '5', '6', '7', '9', '10', '0']
['Hello', '1', '2', '3', '5', '9']
['1', '2', '3', '4', '5', '6 ', '7']
# replace
returnnew string which is replaced by some strings.
a = "100000000000"
print(a.replace("0",""))
b = "HelloWorld"
print(b.replace("World","Hello2"))
c = "1-2-3-4-5-6-7"
print(c.replace("-"," "))
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
OUTPUT
1
HelloHello2
1 2 3 4 5 6 7
# strip
returnnew string which is removed the whitespaces and tabs from head and tail.
a = " Hello World "
print(a.strip())
1
2
2
OUTPUT
Hello World