Skip to content

Commit 300a29c

Browse files
committed
String big changes
1 parent 367ec2f commit 300a29c

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -310,47 +310,49 @@ True
310310
String
311311
------
312312
**Immutable sequence of characters.**
313+
```python
314+
<str> = 'abc' # Also "abc". Interprets \n, \t, \x00-\xff, etc.
315+
```
313316

314317
```python
315318
<str> = <str>.strip() # Strips all whitespace characters from both ends.
316319
<str> = <str>.strip('<chars>') # Strips passed characters. Also lstrip/rstrip().
317320
```
318321

319322
```python
320-
<list> = <str>.split() # Splits on one or more whitespace characters.
323+
<list> = <str>.split() # Splits it on one or more whitespace characters.
321324
<list> = <str>.split(sep=None, maxsplit=-1) # Splits on 'sep' string at most 'maxsplit' times.
322325
<list> = <str>.splitlines(keepends=False) # On [\n\r\f\v\x1c-\x1e\x85\u2028\u2029] and \r\n.
323-
<str> = <str>.join(<coll_of_strings>) # Joins elements by using string as a separator.
326+
<str> = <str>.join(<coll_of_strings>) # Joins items by using the string as a separator.
324327
```
325328

326329
```python
327-
<bool> = <sub_str> in <str> # Checks if string contains the substring.
328-
<bool> = <str>.startswith(<sub_str>) # Pass tuple of strings for multiple options.
330+
<bool> = <sub_str> in <str> # Returns True if string contains the substring.
331+
<bool> = <str>.startswith(<sub_str>) # Pass tuple of strings to give multiple options.
329332
<int> = <str>.find(<sub_str>) # Returns start index of the first match or -1.
330333
```
331334

332335
```python
333336
<str> = <str>.lower() # Lowers the case. Also upper/capitalize/title().
334-
<str> = <str>.casefold() # Same, but converts ẞ/ß to ss, Σ/ς to σ, etc.
337+
<str> = <str>.casefold() # Lower() that converts ẞ/ß to ss, Σ/ς to σ, etc.
335338
<str> = <str>.replace(old, new [, count]) # Replaces 'old' with 'new' at most 'count' times.
336339
<str> = <str>.translate(<table>) # Use `str.maketrans(<dict>)` to generate table.
337340
```
338341

339342
```python
340-
<str> = chr(<int>) # Converts passed integer to Unicode character.
341-
<int> = ord(<str>) # Converts passed Unicode character to integer.
343+
<str> = chr(<int>) # Converts passed integer into Unicode character.
344+
<int> = ord(<str>) # Converts passed Unicode character into integer.
342345
```
343346
* **Use `'unicodedata.normalize("NFC", <str>)'` on strings like `'Motörhead'` before comparing them to other strings, because `'ö'` can be stored as one or two characters.**
344347
* **`'NFC'` converts such characters to a single character, while `'NFD'` converts them to two.**
345348

346-
### Property Methods
347349
```python
348-
<bool> = <str>.isdecimal() # Checks for [0-9]. Also [०-९] and [٠-٩].
349-
<bool> = <str>.isdigit() # Checks for [²³¹…] and isdecimal().
350-
<bool> = <str>.isnumeric() # Checks for [¼½¾…], [零〇一…] and isdigit().
351-
<bool> = <str>.isalnum() # Checks for [a-zA-Z…] and isnumeric().
352-
<bool> = <str>.isprintable() # Checks for [ !#$%…] and isalnum().
353-
<bool> = <str>.isspace() # Checks for [ \t\n\r\f\v\x1c-\x1f\x85…].
350+
<bool> = <str>.isdecimal() # Checks all chars for [0-9]. Also [०-९], [٠-٩].
351+
<bool> = <str>.isdigit() # Checks for [²³¹…] and isdecimal(). Also [፩-፱].
352+
<bool> = <str>.isnumeric() # Checks for [¼½¾…] and isdigit(). Also [零〇一…].
353+
<bool> = <str>.isalnum() # Checks for [ABC…] and isnumeric(). Also [ªµº…].
354+
<bool> = <str>.isprintable() # Checks for [ !"#$…] and isalnum(). Also emojis.
355+
<bool> = <str>.isspace() # Checks for [ \t\n\r\f\v\x1c\x1d\x1e\x1f\x85…].
354356
```
355357

356358

index.html

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
<body>
5858
<header>
59-
<aside>September 8, 2025</aside>
59+
<aside>September 16, 2025</aside>
6060
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
6161
</header>
6262

@@ -304,40 +304,41 @@
304304
┃ decimal.Decimal │ ✓ │ │ │ │ ┃
305305
┗━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┛
306306
</code></pre>
307-
<div><h2 id="string"><a href="#string" name="string">#</a>String</h2><p><strong>Immutable sequence of characters.</strong></p><pre><code class="python language-python hljs">&lt;str&gt; = &lt;str&gt;.strip() <span class="hljs-comment"># Strips all whitespace characters from both ends.</span>
308-
&lt;str&gt; = &lt;str&gt;.strip(<span class="hljs-string">'&lt;chars&gt;'</span>) <span class="hljs-comment"># Strips passed characters. Also lstrip/rstrip().</span>
307+
<div><h2 id="string"><a href="#string" name="string">#</a>String</h2><p><strong>Immutable sequence of characters.</strong></p><pre><code class="python language-python hljs">&lt;str&gt; = <span class="hljs-string">'abc'</span> <span class="hljs-comment"># Also "abc". Interprets \n, \t, \x00-\xff, etc.</span>
309308
</code></pre></div>
310309

311310

312-
<pre><code class="python language-python hljs">&lt;list&gt; = &lt;str&gt;.split() <span class="hljs-comment"># Splits on one or more whitespace characters.</span>
311+
<pre><code class="python language-python hljs">&lt;str&gt; = &lt;str&gt;.strip() <span class="hljs-comment"># Strips all whitespace characters from both ends.</span>
312+
&lt;str&gt; = &lt;str&gt;.strip(<span class="hljs-string">'&lt;chars&gt;'</span>) <span class="hljs-comment"># Strips passed characters. Also lstrip/rstrip().</span>
313+
</code></pre>
314+
<pre><code class="python language-python hljs">&lt;list&gt; = &lt;str&gt;.split() <span class="hljs-comment"># Splits it on one or more whitespace characters.</span>
313315
&lt;list&gt; = &lt;str&gt;.split(sep=<span class="hljs-keyword">None</span>, maxsplit=<span class="hljs-number">-1</span>) <span class="hljs-comment"># Splits on 'sep' string at most 'maxsplit' times.</span>
314316
&lt;list&gt; = &lt;str&gt;.splitlines(keepends=<span class="hljs-keyword">False</span>) <span class="hljs-comment"># On [\n\r\f\v\x1c-\x1e\x85\u2028\u2029] and \r\n.</span>
315-
&lt;str&gt; = &lt;str&gt;.join(&lt;coll_of_strings&gt;) <span class="hljs-comment"># Joins elements by using string as a separator.</span>
317+
&lt;str&gt; = &lt;str&gt;.join(&lt;coll_of_strings&gt;) <span class="hljs-comment"># Joins items by using the string as a separator.</span>
316318
</code></pre>
317-
<pre><code class="python language-python hljs">&lt;bool&gt; = &lt;sub_str&gt; <span class="hljs-keyword">in</span> &lt;str&gt; <span class="hljs-comment"># Checks if string contains the substring.</span>
318-
&lt;bool&gt; = &lt;str&gt;.startswith(&lt;sub_str&gt;) <span class="hljs-comment"># Pass tuple of strings for multiple options.</span>
319+
<pre><code class="python language-python hljs">&lt;bool&gt; = &lt;sub_str&gt; <span class="hljs-keyword">in</span> &lt;str&gt; <span class="hljs-comment"># Returns True if string contains the substring.</span>
320+
&lt;bool&gt; = &lt;str&gt;.startswith(&lt;sub_str&gt;) <span class="hljs-comment"># Pass tuple of strings to give multiple options.</span>
319321
&lt;int&gt; = &lt;str&gt;.find(&lt;sub_str&gt;) <span class="hljs-comment"># Returns start index of the first match or -1.</span>
320322
</code></pre>
321323
<pre><code class="python language-python hljs">&lt;str&gt; = &lt;str&gt;.lower() <span class="hljs-comment"># Lowers the case. Also upper/capitalize/title().</span>
322-
&lt;str&gt; = &lt;str&gt;.casefold() <span class="hljs-comment"># Same, but converts ẞ/ß to ss, Σ/ς to σ, etc.</span>
324+
&lt;str&gt; = &lt;str&gt;.casefold() <span class="hljs-comment"># Lower() that converts ẞ/ß to ss, Σ/ς to σ, etc.</span>
323325
&lt;str&gt; = &lt;str&gt;.replace(old, new [, count]) <span class="hljs-comment"># Replaces 'old' with 'new' at most 'count' times.</span>
324326
&lt;str&gt; = &lt;str&gt;.translate(&lt;table&gt;) <span class="hljs-comment"># Use `str.maketrans(&lt;dict&gt;)` to generate table.</span>
325327
</code></pre>
326-
<pre><code class="python language-python hljs">&lt;str&gt; = chr(&lt;int&gt;) <span class="hljs-comment"># Converts passed integer to Unicode character.</span>
327-
&lt;int&gt; = ord(&lt;str&gt;) <span class="hljs-comment"># Converts passed Unicode character to integer.</span>
328+
<pre><code class="python language-python hljs">&lt;str&gt; = chr(&lt;int&gt;) <span class="hljs-comment"># Converts passed integer into Unicode character.</span>
329+
&lt;int&gt; = ord(&lt;str&gt;) <span class="hljs-comment"># Converts passed Unicode character into integer.</span>
328330
</code></pre>
329331
<ul>
330332
<li><strong>Use <code class="python hljs"><span class="hljs-string">'unicodedata.normalize("NFC", &lt;str&gt;)'</span></code> on strings like <code class="python hljs"><span class="hljs-string">'Motörhead'</span></code> before comparing them to other strings, because <code class="python hljs"><span class="hljs-string">'ö'</span></code> can be stored as one or two characters.</strong></li>
331333
<li><strong><code class="python hljs"><span class="hljs-string">'NFC'</span></code> converts such characters to a single character, while <code class="python hljs"><span class="hljs-string">'NFD'</span></code> converts them to two.</strong></li>
332334
</ul>
333-
<div><h3 id="propertymethods">Property Methods</h3><pre><code class="python language-python hljs">&lt;bool&gt; = &lt;str&gt;.isdecimal() <span class="hljs-comment"># Checks for [0-9]. Also [०-९] and [٠-٩].</span>
334-
&lt;bool&gt; = &lt;str&gt;.isdigit() <span class="hljs-comment"># Checks for [²³¹…] and isdecimal().</span>
335-
&lt;bool&gt; = &lt;str&gt;.isnumeric() <span class="hljs-comment"># Checks for [¼½¾…], [零〇一…] and isdigit().</span>
336-
&lt;bool&gt; = &lt;str&gt;.isalnum() <span class="hljs-comment"># Checks for [a-zA-Z…] and isnumeric().</span>
337-
&lt;bool&gt; = &lt;str&gt;.isprintable() <span class="hljs-comment"># Checks for [ !#$%…] and isalnum().</span>
338-
&lt;bool&gt; = &lt;str&gt;.isspace() <span class="hljs-comment"># Checks for [ \t\n\r\f\v\x1c-\x1f\x85…].</span>
339-
</code></pre></div>
340-
335+
<pre><code class="python language-python hljs">&lt;bool&gt; = &lt;str&gt;.isdecimal() <span class="hljs-comment"># Checks all chars for [0-9]. Also [०-९], [٠-٩].</span>
336+
&lt;bool&gt; = &lt;str&gt;.isdigit() <span class="hljs-comment"># Checks for [²³¹…] and isdecimal(). Also [፩-፱].</span>
337+
&lt;bool&gt; = &lt;str&gt;.isnumeric() <span class="hljs-comment"># Checks for [¼½¾…] and isdigit(). Also [零〇一…].</span>
338+
&lt;bool&gt; = &lt;str&gt;.isalnum() <span class="hljs-comment"># Checks for [ABC…] and isnumeric(). Also [ªµº…].</span>
339+
&lt;bool&gt; = &lt;str&gt;.isprintable() <span class="hljs-comment"># Checks for [ !"#$…] and isalnum(). Also emojis.</span>
340+
&lt;bool&gt; = &lt;str&gt;.isspace() <span class="hljs-comment"># Checks for [ \t\n\r\f\v\x1c\x1d\x1e\x1f\x85…].</span>
341+
</code></pre>
341342
<div><h2 id="regex"><a href="#regex" name="regex">#</a>Regex</h2><p><strong>Functions for regular expression matching.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> re
342343
&lt;str&gt; = re.sub(<span class="hljs-string">r'&lt;regex&gt;'</span>, new, text, count=<span class="hljs-number">0</span>) <span class="hljs-comment"># Substitutes all occurrences with 'new'.</span>
343344
&lt;list&gt; = re.findall(<span class="hljs-string">r'&lt;regex&gt;'</span>, text) <span class="hljs-comment"># Returns all occurrences of the pattern.</span>
@@ -2933,7 +2934,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
29332934

29342935

29352936
<footer>
2936-
<aside>September 8, 2025</aside>
2937+
<aside>September 16, 2025</aside>
29372938
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
29382939
</footer>
29392940

0 commit comments

Comments
 (0)