Skip to content

Commit 0ec4301

Browse files
committed
String
1 parent 8ace934 commit 0ec4301

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

README.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -320,35 +320,33 @@ String
320320
<int> = <str>.index(<sub_str>) # Same but raises ValueError if missing.
321321
```
322322

323-
```python
324-
<bool> = <str>.isdecimal() # True if str contains only [0-9], [٠-٩], …
325-
<bool> = <str>.isdigit() # Also true if str contains '¹²³…'.
326-
<bool> = <str>.isnumeric() # Also true if str contains '¼½¾…'.
327-
```
328-
329323
```python
330324
<str> = <str>.replace(old, new [, count]) # Replaces 'old' with 'new' at most 'count' times.
325+
<str> = <str>.translate(<table>) # Use `str.maketrans(<dict>)` to generate table.
331326
<list> = textwrap.wrap(<str>, width) # Nicely breaks string into lines.
332327
```
333-
334328
* **Also: `'lstrip()'`, `'rstrip()'`.**
335329
* **Also: `'lower()'`, `'upper()'`, `'capitalize()'` and `'title()'`.**
336330

331+
### Properties
332+
```text
333+
+---------------+----------+----------+----------+----------+----------+----------+
334+
| | [\t\n\r] | [ !#$%…] | [A-Za-z] | [¼½¾…] | [¹²³…] | [0-9] |
335+
+---------------+----------+----------+----------+----------+----------+----------+
336+
| isprintable() | | yes | yes | yes | yes | yes |
337+
| isalnum() | | | yes | yes | yes | yes |
338+
| isnumeric() | | | | yes | yes | yes |
339+
| isdigit() | | | | | yes | yes |
340+
| isdecimal() | | | | | | yes |
341+
+---------------+----------+----------+----------+----------+----------+----------+
342+
```
343+
337344
### Char
338345
```python
339346
<str> = chr(<int>) # Converts int to unicode char.
340347
<int> = ord(<str>) # Converts unicode char to int.
341348
```
342349

343-
```python
344-
>>> ord('0'), ord('9')
345-
(48, 57)
346-
>>> ord('A'), ord('Z')
347-
(65, 90)
348-
>>> ord('a'), ord('z')
349-
(97, 122)
350-
```
351-
352350

353351
Regex
354352
-----

index.html

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -432,28 +432,29 @@
432432
&lt;int&gt; = &lt;str&gt;.find(&lt;sub_str&gt;) <span class="hljs-comment"># Returns start index of first match or -1.</span>
433433
&lt;int&gt; = &lt;str&gt;.index(&lt;sub_str&gt;) <span class="hljs-comment"># Same but raises ValueError if missing.</span>
434434
</code></pre>
435-
<pre><code class="python language-python hljs">&lt;bool&gt; = &lt;str&gt;.isdecimal() <span class="hljs-comment"># True if str contains only [0-9], [٠-٩], …</span>
436-
&lt;bool&gt; = &lt;str&gt;.isdigit() <span class="hljs-comment"># Also true if str contains '¹²³…'.</span>
437-
&lt;bool&gt; = &lt;str&gt;.isnumeric() <span class="hljs-comment"># Also true if str contains '¼½¾…'.</span>
438-
</code></pre>
439435
<pre><code class="python language-python hljs">&lt;str&gt; = &lt;str&gt;.replace(old, new [, count]) <span class="hljs-comment"># Replaces 'old' with 'new' at most 'count' times.</span>
436+
&lt;str&gt; = &lt;str&gt;.translate(&lt;table&gt;) <span class="hljs-comment"># Use `str.maketrans(&lt;dict&gt;)` to generate table.</span>
440437
&lt;list&gt; = textwrap.wrap(&lt;str&gt;, width) <span class="hljs-comment"># Nicely breaks string into lines.</span>
441438
</code></pre>
442439
<ul>
443440
<li><strong>Also: <code class="python hljs"><span class="hljs-string">'lstrip()'</span></code>, <code class="python hljs"><span class="hljs-string">'rstrip()'</span></code>.</strong></li>
444441
<li><strong>Also: <code class="python hljs"><span class="hljs-string">'lower()'</span></code>, <code class="python hljs"><span class="hljs-string">'upper()'</span></code>, <code class="python hljs"><span class="hljs-string">'capitalize()'</span></code> and <code class="python hljs"><span class="hljs-string">'title()'</span></code>.</strong></li>
445442
</ul>
443+
<div><h3 id="properties">Properties</h3><pre><code class="text language-text">+---------------+----------+----------+----------+----------+----------+----------+
444+
| | [\t\n\r] | [ !#$%…] | [A-Za-z] | [¼½¾…] | [¹²³…] | [0-9] |
445+
+---------------+----------+----------+----------+----------+----------+----------+
446+
| isprintable() | | yes | yes | yes | yes | yes |
447+
| isalnum() | | | yes | yes | yes | yes |
448+
| isnumeric() | | | | yes | yes | yes |
449+
| isdigit() | | | | | yes | yes |
450+
| isdecimal() | | | | | | yes |
451+
+---------------+----------+----------+----------+----------+----------+----------+
452+
</code></pre></div>
453+
446454
<div><h3 id="char">Char</h3><pre><code class="python language-python hljs">&lt;str&gt; = chr(&lt;int&gt;) <span class="hljs-comment"># Converts int to unicode char.</span>
447455
&lt;int&gt; = ord(&lt;str&gt;) <span class="hljs-comment"># Converts unicode char to int.</span>
448456
</code></pre></div>
449457

450-
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>ord(<span class="hljs-string">'0'</span>), ord(<span class="hljs-string">'9'</span>)
451-
(<span class="hljs-number">48</span>, <span class="hljs-number">57</span>)
452-
<span class="hljs-meta">&gt;&gt;&gt; </span>ord(<span class="hljs-string">'A'</span>), ord(<span class="hljs-string">'Z'</span>)
453-
(<span class="hljs-number">65</span>, <span class="hljs-number">90</span>)
454-
<span class="hljs-meta">&gt;&gt;&gt; </span>ord(<span class="hljs-string">'a'</span>), ord(<span class="hljs-string">'z'</span>)
455-
(<span class="hljs-number">97</span>, <span class="hljs-number">122</span>)
456-
</code></pre>
457458
<div><h2 id="regex"><a href="#regex" name="regex">#</a>Regex</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> re
458459
&lt;str&gt; = re.sub(&lt;regex&gt;, new, text, count=<span class="hljs-number">0</span>) <span class="hljs-comment"># Substitutes all occurrences.</span>
459460
&lt;list&gt; = re.findall(&lt;regex&gt;, text) <span class="hljs-comment"># Returns all occurrences.</span>

web/script_2.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ const DIAGRAM_11_B =
205205
'┃ 4 │ -2147483648 │ 0 │ 2147483647 ┃\n' +
206206
'┗━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━┷━━━━━━━━━━━━━┛\n';
207207

208+
const DIAGRAM_12_A =
209+
'+---------------+----------+----------+----------+----------+----------+----------+\n';
210+
211+
const DIAGRAM_12_B =
212+
'┏━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┓\n' +
213+
'┃ │ [\\t\\n\\r] │ [ !#$%…] │ [A-Za-z] │ [¼½¾…] │ [¹²³…] │ [0-9] ┃\n' +
214+
'┠───────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┨\n' +
215+
'┃ isprintable() │ │ ✓ │ ✓ │ ✓ │ ✓ │ ✓ ┃\n' +
216+
'┃ isalnum() │ │ │ ✓ │ ✓ │ ✓ │ ✓ ┃\n' +
217+
'┃ isnumeric() │ │ │ │ ✓ │ ✓ │ ✓ ┃\n' +
218+
'┃ isdigit() │ │ │ │ │ ✓ │ ✓ ┃\n' +
219+
'┃ isdecimal() │ │ │ │ │ │ ✓ ┃\n' +
220+
'┗━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┛\n';
208221

209222
// isFontAvailable:
210223
(function(d){function c(c){b.style.fontFamily=c;e.appendChild(b);f=b.clientWidth;e.removeChild(b);return f}var f,e=d.body,b=d.createElement("span");b.innerHTML=Array(100).join("wi");b.style.cssText=["position:absolute","width:auto","font-size:128px","left:-99999px"].join(" !important;");var g=c("monospace"),h=c("serif"),k=c("sans-serif");window.isFontAvailable=function(b){return g!==c(b+",monospace")||k!==c(b+",sans-serif")||h!==c(b+",serif")}})(document);
@@ -221,6 +234,7 @@ if (isFontAvailable('Menlo')) {
221234
$(`code:contains(${DIAGRAM_9_A})`).html(DIAGRAM_9_B);
222235
$(`code:contains(${DIAGRAM_10_A})`).html(DIAGRAM_10_B);
223236
$(`code:contains(${DIAGRAM_11_A})`).html(DIAGRAM_11_B);
237+
$(`code:contains(${DIAGRAM_12_A})`).html(DIAGRAM_12_B);
224238
}
225239

226240
var isMobile = false;

0 commit comments

Comments
 (0)