-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringmethods.py
44 lines (31 loc) · 1.01 KB
/
stringmethods.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
#strings are immutable
a="!!!!Vishwa!!!!!"
print("Length of the string is:",len(a))
print(a.upper())
print(a.lower())
print(a.rstrip("!"))#it does not trails the leading characters which are for the stripping
print(a.replace("Vishwa","John"))
blogheading="welcome to home"
print(blogheading.capitalize())
str1="Welcome to the console!!!"
print(str1.center(50))
print(str1.endswith("!!"))
str3= "abababchhadbhsa"
print(str3.count("a"))
#endswith complex example
print("Endswith example",str1.endswith("to",4, 10))
#find method
str1="He's name is Dan .He is an honest Man."
print(str1.find("is"))#only for 1st occurence
#for the alphanumeric charactristics
str1="WelcomeToConsole"
print("isalnum:",str1.isalnum())
print("isapha:",str1.isalpha())
print("islower:",str1.islower())
print("isprintable: ",str1.isprintable())
str1=" "
print(str1.isspace())
str1="Vishwa is a stduent"
print(str1.startswith("Vishwa"))
#to replace uppercase with the lower case
print(str1.swapcase())