-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay_13 String Methods in Python
80 lines (59 loc) · 1.95 KB
/
Day_13 String Methods in Python
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
69
70
71
72
73
74
75
76
77
78
79
80
# Strings are immutable
a = "Karan"
print(len(a))
print(a.upper())
print(a.lower())
#Q: Will it convert first string to lower or upper?
# Ans: No, because strings are immutable so it will create new string of upper/lower case
b = "Omkar!!!!!"
print(b)
print(b.rstrip('!'))
print(b.replace('Omkar', 'Karan'))
c = "!!!!!Karan !!!!!!!!!! Karan"
print(c.split(" "))
blog = "introduction to python"
print(blog.capitalize())
kp = "Welcome to python programming!!"
print(kp.center(50))
#It left 50 spaces before printing the given string
e = "Hi, Karan what are you doing Karan, Karan which lab do you have now?"
print(e.count("Karan"))
k = "Hey, what are you doing?"
print(k.endswith("?"))
print(k.endswith("!!!"))
print(k[5:12])
print(k.endswith("r",5,12))
print(k.find("are"))
print(k.find("aree"))
# print(k.index("aree"))
#This will give you error because it doesn't in the given string.
l = "Whatareyoudoing"
m = "What are you doing"
n = "Whatareyoudoing009"
print(l.isalnum())
print(m.isalnum())
print(n.isalnum())
# alpha-numeric means: No space or any other notations only (A-Z,a-z,0-9,)
print(l.isalpha())
print(m.isalpha())
print(n.isalpha())
# isalpha means: only consider (A-Z,a-z)
v = "We wish you a very Happy New Year"
print(v.isprintable())
x = "We wish you a very Happy New Year\n"
# It's not printable due to \n because it is not the part of string we want to print.
print(x.isprintable())
p = " " #Applied space using space bar(i.e. whitespace)
print(p.isspace())
q = " " #Applied space using tab (i.e. whitespace)
print(q.isspace())
h = "Hi My Name Is Karan"
print(h.istitle())
i = "Hi my name is Karan"
print(i.istitle())
# It returns True if first letter of each word of the string is capital, else it returns false
j = "Hey my name is Karan"
print(j.startswith("Hey"))
print(j.startswith("name"))
print(j.swapcase()) #It converts lower-case to upper-case and vice-versa
print(j.title()) #It capitalizes each letter of the word within the string