SHOW:
|
|
- or go back to the newest paste.
1 | ''' | |
2 | Exercise 6.3 Encapsulate this code in a function named count, and generalize it so that it | |
3 | - | |
3 | + | |
4 | ''' | |
5 | def count(w,l): | |
6 | count = 0 | |
7 | for letter in w: | |
8 | if letter == l: | |
9 | count = count + 1 | |
10 | print count | |
11 | - | |
11 | + | |
12 | ''' | |
13 | Exercise 6.4 There is a string method called count that is similar to the function in the previous | |
14 | exercise. Read the documentation of this method at docs.python.org/library/string. | |
15 | - | |
15 | + | |
16 | ''' | |
17 | - | |
17 | + | |
18 | ''' | |
19 | Exercise 6.5 Take the following Python code that stores a string:‘ | |
20 | str = ’X-DSPAM-Confidence:0.8475’ | |
21 | - | |
21 | + | |
22 | ''' | |
23 | s ='X-DSPAM-Confidence:0.8475' | |
24 | a=s.find(':') | |
25 | b=s[a+1:len(s)] | |
26 | - | |
26 | + | |
27 | ''' | |
28 | Exercise 6.6 Read the documentation of the string methods at docs.python.org/lib/ | |
29 | string-methods.html. You might want to experiment with some of them to make sure you | |
30 | understand how they work. strip and replace are particularly useful. | |
31 | - | |
31 | + | |
32 | ''' | |
33 | s='softvision' | |
34 | print strip(s,'soft') | |
35 | print replace(s,'soft','hard') |