-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday_07strings.py
More file actions
122 lines (79 loc) · 1.91 KB
/
Copy pathday_07strings.py
File metadata and controls
122 lines (79 loc) · 1.91 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#-----------------------------------------
# day_07String
#-----------------------------------------
#1.Accessing of strings
s="GOOD"
print("Accessing the characters of the string:")
print("Positive Indexing:")
print("First character:",s[0])
print("Second character:",s[1])
print("Third character:",s[2])
print("Fourth character:",s[3])
print("Negative Indexing:")
print("Fourth character:",s[-1])
print("Third character:",s[-2])
print("Second character:",s[-3])
print("First character:",s[-4])
#-----------------------------------------
#2.Slicing
s="WELCOME"
print("Slicing:")
print(s[2:5:1])
print(s[0:4:2])
print(s[1:6])
print(s[:5])
print(s[4:])
#-----------------------------------------
#3.Stride
s="FANTASY"
print("String after striding:")
print(s[::3])
print(s[::2])
print(s[::5])
#----------------------------------------
#4.Reversing using loop
org_str="WELCOME"
a=len(org_str)
print("The original String is", org_str)
print("The reverse of the given String is", )
for i in range(a-1,-1,-1):
rev_str = org_str[i]
print( rev_str, end=" ")
#-----------------------------------------
#5.Reversing using Stride operator
s="PYTHON"
rev=s[::-1]
print("Reverse of the sring:", rev)
#----------------------------------------
#6.Palindrome check
s = "racecar"
rev = s[::-1]
if s == rev:
print("Palindrome")
else:
print("Not Palindrome")
#----------------------------------------
#7.Vowel count
s = "masterKING"
count = 0
for ch in s:
if ch in "AEIOUaeiou":
count += 1
print(count)
#----------------------------------------
#8.Removing duplicates
s="banana"
result=""
for ch in s:
if ch not in result :
result+=ch
print("String after removing duplicates:",result)
#----------------------------------------
#9.Anagram
s1="triangle"
s2="integral"
if sorted(s1)==sorted(s2):
print("Anagram")
else:
print("Not an Anagram")
#----------------------------------------