-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-format-string.py
More file actions
386 lines (296 loc) · 5.39 KB
/
Copy pathpython-format-string.py
File metadata and controls
386 lines (296 loc) · 5.39 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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
"""
age = 36
txt = f"My name is John, I am {age}"
print(txt)
"""
"""
price = 59
txt = f"The price is {price} dollars"
print(txt)
"""
"""
price = 59
txt = f"The price is {price:.2f} dollars"
print(txt)
"""
"""
txt = f"The price is {20 * 59} dollars"
print(txt)
"""
#Python - Escape Characters
"""
txt = "We are the so-called \"Vikings\"from the north."
print(txt)
"""
"""
txt = 'It\'s alright'
print(txt)
"""
"""
txt = "This will insert one \\ (backslash)."
"""
"""
txt = "Hello\nWorld!
"""
"""
txt = "Hello\rWorld!"
"""
"""
txt = "Hello\tWorld!"
"""
#Python String capitalize() Method
"""
txt = "hello, and welcome to my world."
x = txt.capitalize()
txt = "36 is my age."
txt = "python Is FUN!"
x = txt.capitalize()
print(x)
"""
"""
txt = "Hello, And Welcome To My World!"
x = txt.casefold()
print(x)
"""
"""
txt = "banana"
x = txt.center(20)
x = txt.center(20, "o")
print(x)
"""
"""
txt = "I love apples, are my favorite fruit"
#x = txt.count("apple")
x = txt.count("apple", 10, 24)
print(x)
"""
"""
txt = "My name is Stále"
x = txt.encode()
print(x)
"""
"""
txt = "Hello, welcome to my world."
x = txt.endswith(".")
x = txt.endswith("my world.", 5, 11)
print(x)
"""
"""
txt = "H\te\tl\tl\to"
x = txt.expandtabs(2)
print(x)
"""
"""
txt = "H\te\tl\tl\to"
print(txt)
print(txt.expandtabs())
print(txt.expandtabs(2))
print(txt.expandtabs(4))
print(txt.expandtabs(10))
"""
"""
txt = "Hello, welcome to my world."
x = txt.find("welcome")
x = txt.find("e")
print(x)
"""
"""
txt = "Hello, welcome to my world."
x = txt.find("e", 5, 10)
print(x)
"""
"""
txt = "For only {price:.2f} dollars!"
print(txt.format(price = 49)
"""
"""
txt = "My name is {fname}, I'm {age}".format(fname = "John", age = 26)
txt = "My name is {0}, I'm {1}".format("John", 36)
txt = "My name is {}, I'm {}".format("John", 26)
print(txt)
"""
"""
txt = "We have {:<8} chickens."
txt = "We have {:>8} chickens."
txt = "We have {:^8} chickens."
print(txt.format(49))
"""
"""
txt = "The temperature is {:=8} degrees celsius."
print(txt.format(-5))
"""
"""
txt = "The temperature is between {:+} and {:+} degrees celsius."
txt = "The temperature is between {:-} and {:-} degrees celsius."
txt = "The temperature is between {: } and {: } degrees celsius."
print(txt.format(-3, 7))
"""
"""
txt = "The universe is {:,} years old."
txt = "The universe is {:_} years old."
print(txt.format(138000000))
"""
"""
txt = "The binary version of {0} is {0:b}"
print(txt.format(5))
"""
"""
txt = "We have {:d} chickens."
print(txt.format(0b101))
"""
"""
txt = "We have {:e} chickens."
txt = "We have {:E} chickens."
print(txt.format(5))
"""
"""
txt = "The price is {:.2f} dollars."
print(txt.format(45))
txt = "The price is {:f} dollars."
print(txt.format(45))
"""
"""
txt = "The octal version of {0} is {0:o}"
print(txt.format(10))
"""
"""
txt = "The Hexadecimal version of {0} is {0:x}"
txt = "The Hexadecimal version of {0} is {0:X}"
print(txt.format(255))
"""
"""
txt = "You scored {:%}"
print(txt.format(0.25))
txt = "You scored {:.0%}"
print(txt.format(0.25))
"""
"""myTuple = ("John", "Peter", "Vicky")
x = "#".join(myTuple)
print(x)
"""
"""txt = "banana"
x = txt.ljust(20)
print(x, "is my favorite fruit.")
"""
"""txt = "Hello Sam!"
mytable = str.maketrans("S", "P")
print(txt.translate(mytable))
"""
"""txt = "I could eat bananas all day"
x = txt.partition("bananas")
print(x)
"""
"""txt = "I like bananas"
x = txt.replace("bananas", "apples")
print(x)
"""
"""
txt = "Mi casa, su casa."
x = txt.rfind("casa")
print(x)
"""
"""txt = "Mi casa, sua casa."
x = txt.rindex("casa")
print(x)
"""
"""txt = "banana"
x = txt.rjust(20)
print(x, "is my favorite fruit")
"""
"""txt = "I could eat bananas all day, bananas are my favorite fruit."
x = txt.rpartition("bananas")
print(x)
"""
"""txt = "apple, banana, cherry"
x = txt.rsplit(", ")
print(x)
"""
"""
txt = "bananas,,,,,,,,,,ssssqqqw......"
x = txt.rstrip(",.qsw")
print(x)
"""
"""
txt = "welcome to the jungle"
x = txt.split()
print(x)
"""
"""txt = "Thank you for the music\nWelcome to the jungle"
x = txt.splitlines()
print(x)
"""
"""
txt = "Hello, welcome to my world."
x = txt.startswith("Hello")
print(x)
"""
"""txt = "Hello, welcome to my world."
x = txt.startswith("wel", 7, 20)
print(x)
"""
"""txt = " banana "
x = txt.strip()
print("of all fruits", x, "is my favorite")
"""
"""txt = ",,,,,,,,,,,,rrttgg......banana.....rrrr"
x = txt.strip(",.grt")
print(x)
"""
"""txt = "Hello My Name Is PETER"
x = txt.swapcase()
print(x)
"""
"""txt = "Welcome to my world"
txt = "Welcome to my 2nd world"
txt = "hello b2b2b2 and 3g3g3g"
x = txt.title()
print(x)
"""
#use a dictionary with ascii codes to replace 83 (S) with 80 (P):
"""
mydict = {83: 80}
txt = "Hello Sam!"
print(txt.translate(mydict))
"""
"""
txt = "Hello Sam!"
mytable = str.maketrans("S", "P")
print(txt.translate(mytable))
"""
"""txt = "Hi Sam!"
x = "mSa"
y = "eJo"
mytable = str.maketrans(x, y)
print(txt.translate(mytable))
"""
"""
txt = "Good night Sam!"
x = "mSa"
y = "eJo"
z = "odnght"
mytable = str.maketrans(x, y, z)
print(txt.translate(mytable))
"""
"""
txt = "Good night Sam!"
mydict = {109: 101, 83: 74, 97: 111,111: None, 100: None, 110: None, 103: None, 104: None, 116: None}
print(txt.translate(mydict))
"""
"""
txt = "Hello my friends"
x = txt.upper()
print(x)
"""
"""
txt = "50"
x = txt.zfill(10)
print(x)
"""
"""
a = "hello"
b = "welcome to the jungle"
c = "10.000"
print(a.zfill(10))
print(b.zfill(10))
print(c.zfill(10))
"""