Skip to content

Commit 73353c8

Browse files
authored
Update 05-Strings.md
1 parent 3444ba7 commit 73353c8

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

python/05-Strings.md

+19-18
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ text = 'The value of pi is ' + str(pi) ## yes
3333
3434
<h2>Functions</h2>
3535

36-
| <center>Function </center> | <center>What it does</center>
37-
| :------------- | :-------------
38-
| <a>s.lower(), s.upper()</a> |Returns the lowercase or uppercase version of the string
39-
| <a>s.strip()</a> |Returns a string with whitespace removed from the start and end
36+
| <center>Function </center> | <center>What it does</center>
37+
| :------------- | :-------------
38+
| <a>s.lower(), s.upper()</a> | Returns the lowercase or uppercase version of the string
39+
| <a>s.strip()</a> |Returns a string with whitespace removed from the start and end
4040
| <a>s.isalpha(), s.isdigit(), s.isspace()</a> |Tests if all the string chars are in the various character classes
41-
| <a>s.startswith('other'), s.endswith('other')</a> |Tests if the string starts or ends with the given other string
42-
| <a>s.find('other')</a> |Searches for the given other string (not a regular expression) within s, and returns the first index where it begins or -1 if not found
43-
| <a>s.replace('old', 'new') </a> |Returns a string where all occurrences of 'old' have been replaced by 'new'
44-
| <a>s.split('delim') </a> |Returns a list of substrings separated by the given delimiter. The delimiter is not a regular expression, it's just text. 'aaa,bbb,ccc'.split(',') -> ['aaa', 'bbb', 'ccc']. As a convenient special case s.split() (with no arguments) splits on all whitespace chars.
45-
| <a>s.join(list) </a> |Opposite of split(), joins the elements in the given list together using the string as the delimiter. e.g. '---'.join(['aaa', 'bbb', 'ccc']) -> aaa---bbb---ccc
41+
| <a>s.startswith('other'), s.endswith('other')</a> |Tests if the string starts or ends with the given other string
42+
| <a>s.find('other')</a> |Searches for the given other string (not a regular expression) within s, and returns the first index where it begins or -1 if not found
43+
| <a>s.replace('old', 'new') </a> |Returns a string where all occurrences of 'old' have been replaced by 'new'
44+
| <a>s.split('delim') </a> |Returns a list of substrings separated by the given delimiter. The delimiter is not a regular expression, it's just text. 'aaa,bbb,ccc'.split(',') -> ['aaa', 'bbb', 'ccc']. As a convenient special case s.split() (with no arguments) splits on all whitespace chars.
45+
| <a>s.join(list) </a> |Opposite of split(), joins the elements in the given list together using the string as the delimiter. e.g. '---'.join(['aaa', 'bbb', 'ccc']) -> aaa---bbb---ccc
46+
4647
</br>
4748

4849
<h2>String Slices</h2>
@@ -51,20 +52,20 @@ text = 'The value of pi is ' + str(pi) ## yes
5152
5253
| <center>Function </center> | <center>What it does</center>
5354
| :------------- | :-------------
54-
| <a>s[1:4] </a> |is 'ell' -- chars starting at index 1 and extending up to but not including index 4
55-
| <a>s[1:]</a> |is 'ello' -- omitting either index defaults to the start or end of the string
56-
| <a>s[:]</a> |is 'Hello' -- omitting both always gives us a copy of the whole thing (this is the pythonic way to copy a sequence like a string or list)
57-
| <a>s[1:100]</a> |an index that is too big is truncated down to the string length
55+
| <a>s[1:4] </a> |is 'ell' -- chars starting at index 1 and extending up to but not including index 4
56+
| <a>s[1:]</a> |is 'ello' -- omitting either index defaults to the start or end of the string
57+
| <a>s[:]</a> |is 'Hello' -- omitting both always gives us a copy of the whole thing (this is the pythonic way to copy a sequence like a string or list)
58+
| <a>s[1:100]</a> |an index that is too big is truncated down to the string length
5859
</br>
5960

6061
>The standard zero-based index numbers give easy access to chars near the start of the string. As an alternative, Python uses negative numbers to give easy access to the chars at the end of the string: s[-1] is the last char 'o', s[-2] is 'l' the next-to-last char, and so on. Negative index numbers count back from the end of the string:</br>
6162
6263
| <center>Function </center> | <center>What it does</center>
6364
| :------------- | :-------------
64-
| <a>s[-1] </a> |is 'o' -- last char (1st from the end)
65-
| <a>s[-4]</a> |is 'e' -- 4th from the end
66-
| <a>s[:-3]</a> |is 'He' -- going up to but not including the last 3 chars
67-
| <a>s[-3:]</a> |is 'llo' -- starting with the 3rd char from the end and extending to the end of the string
65+
| <a>s[-1] </a> |is 'o' -- last char (1st from the end)
66+
| <a>s[-4]</a> |is 'e' -- 4th from the end
67+
| <a>s[:-3]</a> |is 'He' -- going up to but not including the last 3 chars
68+
| <a>s[-3:]</a> |is 'llo' -- starting with the 3rd char from the end and extending to the end of the string
6869
</br>
6970

7071
<h2>String %</h2>
@@ -84,4 +85,4 @@ text = "%d little pigs come out or I'll %s and %s and %s" % (3, 'huff', 'puff',
8485
## add parens to make the long-line work:
8586
text = ("%d little pigs come out or I'll %s and %s and %s" %
8687
(3, 'huff', 'puff', 'blow down'))
87-
```
88+
```

0 commit comments

Comments
 (0)