Skip to content

Commit a437d65

Browse files
committedDec 19, 2023
Add changes to Strings lesson
1 parent 2914d21 commit a437d65

File tree

13 files changed

+60
-25
lines changed

13 files changed

+60
-25
lines changed
 

‎Strings/Basic string methods/task.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ uppercase. To call any string method, type a dot after the string (or a variable
66
the string) and the method name after it, e.g., `"John".upper()`. In PyCharm, you can
77
explore all available string methods by using the &shortcut:CodeCompletion; shortcut after the dot.
88
Detailed information about all string methods can be found <a href="https://docs.python.org/3/library/stdtypes.html#string-methods">here</a>.
9-
9+
10+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6842).
11+
1012
Print `monty_python` in upper case using an appropriate string method.
1113

1214
<div class='hint'>Pay attention to how the <code>lower()</code> method is used in our code.</div>
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
dont_worry = "Don't worry about apostrophes"
2-
# print(dont_worry)
3-
# print("\"Sweet\" is an ice-cream")
1+
dont_worry = "Don't worry about single quote if the string is in double quotes and vice versa"
2+
print(dont_worry)
3+
4+
print("\"Sweet\" is an ice-cream")
5+
46
print('The name of this ice cream is "Sweet\'n\'Tasty"')
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
type: edu
22
files:
3-
- name: character_escaping.py
4-
visible: true
5-
placeholders:
6-
- offset: 109
7-
length: 47
8-
placeholder_text: ???
9-
- name: tests/__init__.py
10-
visible: false
11-
- name: tests/test_task.py
12-
visible: false
13-
feedback_link: https://docs.google.com/forms/d/e/1FAIpQLSfRlDlldKfuq-cHMNFfHMER61P1PRIan7KG6yp1GvaweDI7GA/viewform?usp=pp_url&entry.2103429047=Strings+/+Character+Escaping
3+
- name: character_escaping.py
4+
visible: true
5+
placeholders:
6+
- offset: 157
7+
length: 47
8+
placeholder_text: ???
9+
- name: tests/__init__.py
10+
visible: false
11+
- name: tests/test_task.py
12+
visible: false
13+
feedback_link: https://docs.google.com/forms/d/e/1FAIpQLSfRlDlldKfuq-cHMNFfHMER61P1PRIan7KG6yp1GvaweDI7GA/viewform?usp=pp_url&entry.2103429047=Strings+/+Character+Escaping

‎Strings/Character escaping/task.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ If you need to print quotes inside a string, use a different kind of quotes: sin
1616
marks may be used in a double-quoted string without escaping, and vice versa. Also, as a side note, it is a good
1717
idea to pick your favorite kind of quotes and use them consistently.
1818

19-
You can learn more about escaping from <a href="https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals">this section</a> of Python Documentation.
19+
You can learn more about escaping from <a href="https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals">this section</a> of Python Documentation.
20+
21+
For more structured and detailed information, you can also refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/7130).
2022

2123
Print out the following text using one string:
2224
```text
2325
The name of this ice cream is "Sweet'n'Tasty"
2426
```
2527

26-
2728
<div class='hint'>Use the backslash to escape quotes.</div>

‎Strings/Character escaping/tests/test_task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def test_string(self):
88
f = io.StringIO()
99
with contextlib.redirect_stdout(f):
1010
import character_escaping
11-
output = f.getvalue()[:-1]
11+
output = f.getvalue().split('\n')[-2]
1212
string = 'The name of this ice cream is "Sweet\'n\'Tasty"'
1313
self.assertEqual(string, output, msg='Wrong result string.')
1414

‎Strings/F-strings/task.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ f"{name.lower()} is funny."
2929
```
3030
For more information about formatted string literals you can refer to <a href="https://docs.python.org/3/reference/lexical_analysis.html#formatted-string-literals">Python Docs</a>.
3131

32+
For more structured and detailed information, you can also refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6037).
33+
3234
Try creating an f-string yourself. Also try running the code to see what it prints.
3335

3436
<div class="hint">The value assigned to the <code>name</code> variable has to be a string, so it needs to be in quotes,

‎Strings/String formatting/task.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ or decimal values.
1212
> interface, or <a href="https://docs.python.org/3/library/string.html#template-strings">template strings</a> may help avoid these errors.
1313
> Each of these alternatives provides their own trade-offs and benefits of
1414
> simplicity, flexibility, and/or extensibility.</i>
15-
15+
16+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6037).
17+
1618
Tell PyCharm how old you are (using digits).
1719

1820
<div class='hint'>Use the <code>%d</code> special symbol.</div>

‎Strings/String indexing/task.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ when `x` is not found in the string.
88
Indices may also be negative numbers if you need to start counting from the right
99
(i.e., from the end of your string).
1010
Note that since `-0` is the same as `0` , negative indices start from `-1`.
11-
11+
12+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6189).
13+
1214
Use the index operator to get the letter `"P"` from `"Python"` .
1315

1416
<div class="hint">Note that indices start with 0.</div>

‎Strings/String length/task-info.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ files:
55
placeholders:
66
- offset: 200
77
length: 23
8-
placeholder_text: '"???"'
8+
placeholder_text: ???
99
- offset: 121
1010
length: 20
11-
placeholder_text: '"???"'
11+
placeholder_text: ???
1212
- name: tests/__init__.py
1313
visible: false
1414
- name: tests/test_task.py

‎Strings/String length/task.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
## String length
22

3-
The `len()` method is used to count how many characters a string contains.
4-
3+
The `len()` method is used to count how many characters a string contains.
4+
5+
For example:
6+
```python
7+
s = "Hello World"
8+
print(len(s)) # will print 11
9+
```
10+
11+
Note, that result of `/` division have type float:
12+
```python
13+
a = 10/2
14+
print(a) # 5.0
15+
print(type(a)) # <class 'float'>
16+
```
17+
18+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/5814).
19+
520
Get the first half of the string stored in the variable `phrase`.
621
Note: when getting the index, remember about type conversion.
722

‎Strings/String length/tests/test_task.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ def test_index(self):
1818
class TestCase(unittest.TestCase):
1919
def test_fail(self):
2020
self.assertTrue(False, msg="Do not rename any variables.")
21+
22+
except TypeError:
23+
class TestCase(unittest.TestCase):
24+
def test_fail(self):
25+
self.assertTrue(False, msg="Don't forget to convert the result of division to int type")

‎Strings/String negative indexing/task.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
As we said, you can use negative indices to count characters ‘backwards’ starting
44
from the end of a string.
5-
5+
6+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6189).
7+
68
Use a negative index to get the `'!'` sign from `long_string`.
79

810
<div class='hint'>Use a negative index.</div>

‎Strings/String slicing/task.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ str[:end] # items from the beginning through end-1
2424
str[:] # a copy of the whole array
2525
</code></pre>
2626

27+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/6177).
28+
2729
Use slicing to get `"Python"` from the `monty_python` variable.
2830

2931
<div class='hint'>You can leave one of the indices empty.</div>

0 commit comments

Comments
 (0)