-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17_Python_String_Methods.py
68 lines (56 loc) · 1.28 KB
/
17_Python_String_Methods.py
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
# Python - String Methods
# capitalize()
str1 = "python is easy to learn."
print(str1.capitalize())
print("----------")
# center()
str2 = "center"
print(str2.center(20))
print("")
# count()
str3 = "I like chess, because I am a chess player. And, I believe chess is fun to play."
print(str3.count("chess")) # 3
print("")
# endswith()
str4 = "Data is correct"
print(str4.endswith("correct")) # True
print(str4.endswith("wrong")) # False
print("----------")
# find()
str5 = "Hi, welcome to my channel."
print(str5.find("welcome")) # 4
print(str5.find("channel")) # 18
print("")
# isalnum()
str6 = "alpha123"
print(str6.isalnum()) # True
print("")
# isdigit()
str7 = "812657"
print(str7.isdigit()) # True
str8 = "jaf1999"
print(str8.isdigit()) # False
print("----------")
# islower()
str9 = "all lowercase letters here."
print(str9.islower()) # True
str10 = "Not all LowerCASE letters here."
print(str10.islower()) # False
print("")
# isnumeric()
str11 = "6125498"
print(str11.isnumeric()) # True
str12 = "jaf1999"
print(str12.isnumeric()) # False
print("")
# isspace()
str13 = " "
print(str13.isspace()) # True
print("----------")
# isupper()
str14 = "UPPER LETTERS"
print(str14.isupper()) # True
print("")
# partition()
str15 = "I can play chess anytime."
print(str15.partition("chess"))