-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_practice.py
72 lines (48 loc) · 1.29 KB
/
string_practice.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
69
70
71
72
"""
test = "testing "
print(test[2])
print(test.casefold())
print(test.capitalize())
print(test.isalnum())
print(len(test))
print(test.expandtabs(10))
print(test.isspace())
print(test.__sizeof__())
print(test.format_map(2))
print(test.isupper())
print(test.rsplit(2))
"""
# Print each character of string
username = "Laxmikant"
# first way of printing characters
print(username)
for char in username:
print(char)
# second way of printing characters
for i in range(len(username)):
print(username[i])
# third way of printing characters
i=0
while i <len(username):
print(username[i])
i = i + 1
# Print each character of string in reverse order
# first way of printing characters in reverse
print(username[::-1])
for char in username[::-1]:
print(char)
# second way of printing characters in reverse
i=len(username) -1
while i >= 0:
print(username[i])
i = i - 1
# Third way of printing characters in reverse
for i in range(len(username)-1, -1, -1):
print(i)
print(username[i])
# Replace firstname with last name
fullName = "Laxmikant Mehetre"
print(fullName.replace("Laxmikant","Mehetre"))
fullName = "Laxmikant Mehetre"
for char in fullName.replace("Laxmikant","Mehetre"):
print(char)