-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.py
More file actions
340 lines (288 loc) · 6.14 KB
/
Copy pathstring.py
File metadata and controls
340 lines (288 loc) · 6.14 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
print("String and methods")
# s1 = 'Hello Asif'
# s2 = "Hello Emon"
# s3 = """I am
# 24 years old"""
# print(s1,s2,s3)
# s4 = str(2443.4)
# print(s4,type(s4))
# print("Hi i am 30 year's old")
# print('Hlw How are "you"')
#accessing stings-indexing.slicing
s = "Hello Python"
# print(s[0])
# print(s[6])
# print(s[-1])
# print(s[len(s)-6])
# print(s[15])
#slicing
# print(s[::])
# print(s[::-1])
# print(s[0:6:2])
# print(s[1:5])
# print(s[-1:-5:-1])
# print(s[-1::])
# print(s[-6:])
# print(s[-5:-1])
#editing and deleting strings
# s[0] ="A"
# s1 = s[0]
# print(s1)
# s2 = s[1:4]
# print(s2)
# del s[0]
# del s[0:5]
# del s
# print(s)
#operations on string
# print("Asif"+" "+"Arfi")
# print("Delhi"+ "Mumbai")
# print("Asif"*3)
# print("Asif"-23)
# print("*"*50)
# print("Asif">"Cinema")
# print("Emon">)
#relational operator
# print("Asif"=="Asif")
# print(12 == 12.00)
# print("Dhaka"!="dhaka")
# print("Asif">"Asif")
# print("Asif"<"Emon")
# print('qwer'>="1234")
# print("Asif" and "Afiya")
# print("" and "A")
# print("Asif" or 12)
# print(False and "Asif")
# print(not "")
# print(not "Asif")
# for i in "Hello World":
# print(i)
# s = "Asif is 24 years old"
# for i in range(0,len(s)):
# print(s[i])
#functions-len,min,max,sorted
s = "Hello Asif"
# print(len(s))
# print(max(s))
# print(min(s))
# print(max(''))
# print(sorted(s,reverse=True))
#more functions - capitalize,title,upper,lower,swapcase
s = "hello WoRld"
# print(s.capitalize())
# print(s.title())
# print(s.upper())
# print(s.lower())
# print(s.swapcase())
#count/index/find
# print(s.count('o'))
# print(s.count('l'))
# # print(s.index("7"))
# print(s.find('w'))
# print(s.find(''))
#find the length
# s = input("Enter a string:")
# count = 0
# for i in s:
# count +=1
# print(i)
# print("length is:",count)
# s = input('Enter email:')
# username = ""
# for i in s:
# if i =="@":
# break
# else:
# username +=i
# print("username:",username)
# s = input("enter a string:")
# c = input("enter a character:")
# count =0
# for x in s:
# if x == c:
# count +=1
# print(c," count:",count)
# s = input("enter the string:")
# c = input("enter the character to remove:")
# str1 = ""
# for x in s:
# if x ==c:
# continue
# else:
# str1+=x
# print("modified string:",str1)
#string revise
# s1 = 'Hello Asif'
# s2 = "Hello Python"
# s3 = """Hi
# i am asif"""
# print(s1,s2,s3)
# print("Hello I am 24 year's old")
# print('Hello "Probin ')
# s1 = str(2+3j)
# print(s1)
#accessing string - index,slicing
s1 = "Hello Bangladesh"
# print(s1[0])
# print(s1[-4])
# print(s1[len(s1)-3])
# print(s1[1:4])
# print(s1[::-1])
# print(s1[::])
# print(s1[:4])
# print(s1[-1:-5:-1])
#string is immutable - can't edit the string
s1 = "Hello Bangladesh"
# s1[0] = "As"
# print(s1)
# s1[1:3] = "Asif"
# print(s1[0])
# del s1[0]
# del s1
# print(s1)
#operations on string
#arithmetic - +/*
s1 = "Hello"
# print(s1*3)
# print(s1 + "Asif" + 23)
# print("Mumbai"+"Delhi")
# print("Asif"+"Asif")
#relational - <,<=,>=,>,==,!=
# print("Asif">"Himel")
# print("Asif"<"probin")
# print("Boss" == "Boss")
# print("Boss">"Asif")
# print("Asif"!="asif")
# print("Cat">"Catch")
# print("cat">"CAT")
#string formatting
# name = "Asif"
# age = 24
# print(f"My name is {name} and age is {age}")
# str1 ="My name is {} and age is {}".format(name,age)
# print(str1)
# print("Asif" and "Hasan" and "Probin")
# print("" and "Asif" and "9")
# print("Asif" or False)
# print("" or "AS")
# print(not "Asif")
# print(not "")
# for i in "Hello World":
# print(i)
# for i in range(1,11):
# print(f"Hello World {i}")
#membership operator - in,not in
# print("H" in "Hello")
# print("D" in "delhi")
# print("a" not in "Asif")
#common function - len,max,min,sorted
s1 = "hello world"
# print(len(s1))
# print(max(s1))
# print(min(s1))
# print(sorted(s1,reverse=True))
# print(s1.capitalize())
# print(s1.title())
# print(s1.upper())
# print(s1.lower())
# print(s1.swapcase())
# print(s1.count("o"))
#find the length of a given string
# s = input("Enter a string:")
# counter = 0
# for i in s:
# counter += 1
# print(f"length of string is : {counter}")
# email = input("Enter your email:")
#string revise
# str1 = 'Hello Asif'
# str2 = "Hello Python"
# str3 ="""Multiline
# string"""
# print(str1,str2,str3)
# print("Asif 's")
# print('Asif"ssf')
# str1 = str("Asif")
# print(str1)
s1 = "Hello Python"
# print(s1[4])
# print(s1[-4])
# print(s1[len(s1)-3])
#slicing - [::]
# print(s1[1:5])
# print(s1[::-1])
# print(s1[::])
# print(s1[:5])
# print(s1[-3:-5:-1])
#s1[0] ="A"
# s2 = s1[0:4]
# print(s2)
# s = "Asif"
# # del s[0]
# del s
# print(s)
#operations on string
# print("Asif"+" "+"Asif")
# print("Asif"*3)
# print("Asif">="asif")
# print("Dhaka"<"Pune")
# print("cat">"catch")
#print("Asif"=="asifa")
# print("Asif"and"Asifa")
# print("sif"and"")
# print("" and "Asif")
# print("Asif"or"Shifa")
#print(not 23)
# s1 = "Hello Asif"
# for i in s1:
# print(i)
#print("D" in "Deshi")
# print(12 and 23 and 34)
# print(23 and "" and 34)
#common functions-min,max,len,sorted
# s1 = "Hello Asif"
# print(len(s1))
# print(max(s1))
# print(min(s1))
# print(sorted(s1,reverse=True))
# s1 = "hello World"
# print(s1.capitalize())
# print(s1.upper())
# print(s1.lower())
# print(s1.title())
# print(s1.swapcase())
# s2 = "Hello Python"
# print(s2.swapcase())
# print(s2.lower())
# print(s2.upper())
# print(s2.title())
# print(s2.capitalize())
#string formatting- format,f-string
# name = "Asif"
# age = 25
# print("My name is {} and age is {}".format(name,age))
# print(f"My name is {name} and age is {age}")
#functions to check if a string meets a criteria
# s = "HelloWorld"
# print(s.isalnum())
# s = "!123Asif"
# print(s.isalnum())
# email = "haque.mdasif1501@gmail.com"
# username =""
# for i in email:
# if i =='@':
# break
# else:
# username +=i
# print("Username :{}".format(username))
#count the frequency of a particular character in a string
# s = "hello how are you"
# char = 'h'
# count = 0
# for i in s:
# if i == char:
# count +=1
# print(f"Frequency:{count}")
#remove a particular character from a string
# s = input("Enter a string:")
# char = input("Enter a char:")