1
+ import string
2
+
3
+ # print(string.ascii_letters)
4
+ # print(string.punctuation)
5
+ # print(string.hexdigits)
6
+ # print(string.digits)
7
+
8
+ test_str1 = 'The shells she sells are sea-shell5'
9
+ test_str2 = 'IntergallacticPython'
10
+ test_str3 = '419209'
11
+
12
+ res = "" .join ([c for c in test_str1 if c in string .ascii_letters ])
13
+
14
+ # print(all([c.isalpha() for c in test_str1]))
15
+
16
+ # print(test_str1.isnumeric())
17
+ # print(test_str3.isnumeric())
18
+
19
+ # print(res)
20
+
21
+ # print(test_str1.isalnum())
22
+ # print(test_str2.isalpha())
23
+
24
+ sample_str = 'Peter Piper picked a peck of pickled peppers'
25
+
26
+ # print(sample_str.startswith('Peter'))
27
+ # print(sample_str.startswith('peter'))
28
+ # print(sample_str.endswith('peppers'))
29
+
30
+ # print(sample_str.find('picked'))
31
+ # print(sample_str.rfind('picked'))
32
+
33
+ new_str = sample_str .replace ('pepper' , 'apple' )
34
+ # print(new_str)
35
+
36
+ # print(sample_str.count('a'))
37
+
38
+ sample_str2 = 'Betty Botter bought a bit of butter'
39
+
40
+ # print(sample_str2.upper())
41
+ # print(sample_str2.lower())
42
+
43
+ # split_res = sample_str2.split(" ")
44
+ # print(split_res)
45
+
46
+ # join_res = " ".join(split_res)
47
+ # print(join_res)
48
+
49
+ names = ["Doc" , "Grumpy" , "Bashful" , "Sleepy" , "Happy" , "Sneezy" , "Dopey" ]
50
+ longest = max (len (name ) for name in names )
51
+
52
+ # for name in names:
53
+ # print(name.ljust(longest+2, "-") + ":")
54
+ # for name in names:
55
+ # print(name.center(longest+2, "-") + ":")
56
+ # for name in names:
57
+ # print(name.rjust(longest+2, "-") + ":")
58
+
59
+ the_str = "The quick brown $animal $action over the lazy dog"
60
+ the_template = string .Template (the_str )
61
+ # from string import Template
62
+ # output_str = the_template.substitute(animal='fox', action='jumped')
63
+ # print(output_str)
64
+
65
+ # args = {
66
+ # "animal": "cow",
67
+ # "action": "ran"
68
+ # }
69
+
70
+ # output_str = the_template.substitute(args)
71
+ # print(output_str)
72
+
73
+ product = "laptop"
74
+ price = "199.99"
75
+ tax = 0.08
76
+
77
+ print (f"{ product } has a price of { price } , plus { tax :.2%} tax" )
0 commit comments