Skip to content

Commit 3b885b4

Browse files
authored
Update 05-Strings.md
1 parent 73353c8 commit 3b885b4

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

python/05-Strings.md

+12-10
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,24 @@ text = 'The value of pi is ' + str(pi) ## yes
5050

5151
>The "slice" syntax is a handy way to refer to sub-parts of sequences -- typically strings and lists. The slice s[start:end] is the elements beginning at start and extending up to but not including end. Suppose we have s = "Hello"</br>
5252
53-
| <center>Function </center> | <center>What it does</center>
54-
| :------------- | :-------------
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
53+
| <center>Function </center> | <center>What it does</center>
54+
| :------------- | :-------------
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
59+
5960
</br>
6061

6162
>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>
6263
6364
| <center>Function </center> | <center>What it does</center>
6465
| :------------- | :-------------
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
66+
| <a>s[-1] </a> | is 'o' -- last char (1st from the end)
67+
| <a>s[-4]</a> | is 'e' -- 4th from the end
68+
| <a>s[:-3]</a> | is 'He' -- going up to but not including the last 3 chars
69+
| <a>s[-3:]</a>
70+
| is 'llo' -- starting with the 3rd char from the end and extending to the end of the string
6971
</br>
7072

7173
<h2>String %</h2>

0 commit comments

Comments
 (0)