From 6a70b6a899c338cf4e09eaff1e8fb26c6d38b1b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= <sornjure@gmail.com> Date: Tue, 1 Apr 2025 00:15:02 +0200 Subject: [PATCH] Datetime, Function --- README.md | 10 +++++----- index.html | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 6cdf782..3a8f41a 100644 --- a/README.md +++ b/README.md @@ -374,7 +374,7 @@ import re * **Argument `'flags=re.IGNORECASE'` can be used with all functions.** * **Argument `'flags=re.MULTILINE'` makes `'^'` and `'$'` match the start/end of each line.** * **Argument `'flags=re.DOTALL'` makes `'.'` also accept the `'\n'`.** -* **`'re.compile(<regex>)'` returns a Pattern object with methods sub(), findall(), …** +* **`'re.compile(<regex>)'` returns a Pattern object with methods sub(), findall(), etc.** ### Match Object ```python @@ -500,7 +500,7 @@ Numbers <Fraction> = fractions.Fraction(0, 1) # Or: Fraction(numerator=0, denominator=1) <Decimal> = decimal.Decimal(<str/int>) # Or: Decimal((sign, digits, exponent)) ``` -* **Decimal numbers are stored exactly, unlike most floats where: `'1.1 + 2.2 != 3.3'`.** +* **Decimal numbers are stored exactly, unlike most floats where `'1.1 + 2.2 != 3.3'`.** * **Floats can be compared with: `'math.isclose(<float>, <float>)'`.** * **Precision of decimal operations is set with: `'decimal.getcontext().prec = <int>'`.** * **Bools can be used anywhere ints can, because bool is a subclass of int: `'True + 1 == 2'`.** @@ -655,8 +655,8 @@ import zoneinfo, dateutil.tz >>> dt.strftime("%dth of %B '%y (%a), %I:%M %p %Z") "14th of August '25 (Thu), 11:39 PM UTC+02:00" ``` -* **`'%z'` accepts `'±HH[:]MM'` and returns `'±HHMM'` or empty string if datetime is naive.** -* **`'%Z'` accepts `'UTC/GMT'` and local timezone's code and returns timezone's name, `'UTC[±HH:MM]'` if timezone is nameless, or an empty string if datetime is naive.** +* **`'%z'` accepts `'±HH[:]MM'` and returns `'±HHMM'` or empty string if object is naive.** +* **`'%Z'` accepts `'UTC/GMT'` and local timezone's code and returns timezone's name, `'UTC[±HH:MM]'` if timezone is nameless, or an empty string if object is naive.** ### Arithmetics ```python @@ -679,7 +679,7 @@ def <func_name>(<default_args>): ... # E.g. `def func(x=0, y def <func_name>(<nondefault_args>, <default_args>): ... # E.g. `def func(x, y=0): ...`. ``` * **Function returns None if it doesn't encounter `'return <obj/exp>'` statement.** -* **Before modifying a global variable from within the function run `'global <var_name>'`.** +* **Run `'global <var_name>'` inside the function before assigning to global variable.** * **Default values are evaluated when function is first encountered in the scope. Any mutation of a mutable default value will persist between invocations!** ### Function Call diff --git a/index.html b/index.html index a3ca5c8..07c9c72 100644 --- a/index.html +++ b/index.html @@ -56,7 +56,7 @@ <body> <header> - <aside>March 30, 2025</aside> + <aside>April 1, 2025</aside> <a href="https://gto76.github.io" rel="author">Jure Šorn</a> </header> @@ -356,7 +356,7 @@ Point(x=<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span> <li><strong>Argument <code class="python hljs"><span class="hljs-string">'flags=re.IGNORECASE'</span></code> can be used with all functions.</strong></li> <li><strong>Argument <code class="python hljs"><span class="hljs-string">'flags=re.MULTILINE'</span></code> makes <code class="python hljs"><span class="hljs-string">'^'</span></code> and <code class="python hljs"><span class="hljs-string">'$'</span></code> match the start/end of each line.</strong></li> <li><strong>Argument <code class="python hljs"><span class="hljs-string">'flags=re.DOTALL'</span></code> makes <code class="python hljs"><span class="hljs-string">'.'</span></code> also accept the <code class="python hljs"><span class="hljs-string">'\n'</span></code>.</strong></li> -<li><strong><code class="python hljs"><span class="hljs-string">'re.compile(<regex>)'</span></code> returns a Pattern object with methods sub(), findall(), …</strong></li> +<li><strong><code class="python hljs"><span class="hljs-string">'re.compile(<regex>)'</span></code> returns a Pattern object with methods sub(), findall(), etc.</strong></li> </ul> <div><h3 id="matchobject">Match Object</h3><pre><code class="python language-python hljs"><str> = <Match>.group() <span class="hljs-comment"># Returns the whole match. Also group(0).</span> <str> = <Match>.group(<span class="hljs-number">1</span>) <span class="hljs-comment"># Returns part inside the first brackets.</span> @@ -463,7 +463,7 @@ Point(x=<span class="hljs-number">1</span>, y=<span class="hljs-number">2</span> </code></pre></div> <ul> -<li><strong>Decimal numbers are stored exactly, unlike most floats where: <code class="python hljs"><span class="hljs-string">'1.1 + 2.2 != 3.3'</span></code>.</strong></li> +<li><strong>Decimal numbers are stored exactly, unlike most floats where <code class="python hljs"><span class="hljs-string">'1.1 + 2.2 != 3.3'</span></code>.</strong></li> <li><strong>Floats can be compared with: <code class="python hljs"><span class="hljs-string">'math.isclose(<float>, <float>)'</span></code>.</strong></li> <li><strong>Precision of decimal operations is set with: <code class="python hljs"><span class="hljs-string">'decimal.getcontext().prec = <int>'</span></code>.</strong></li> <li><strong>Bools can be used anywhere ints can, because bool is a subclass of int: <code class="python hljs"><span class="hljs-string">'True + 1 == 2'</span></code>.</strong></li> @@ -585,8 +585,8 @@ shuffle(<list>) <span class="hljs-commen </code></pre></div> <ul> -<li><strong><code class="python hljs"><span class="hljs-string">'%z'</span></code> accepts <code class="python hljs"><span class="hljs-string">'±HH[:]MM'</span></code> and returns <code class="python hljs"><span class="hljs-string">'±HHMM'</span></code> or empty string if datetime is naive.</strong></li> -<li><strong><code class="python hljs"><span class="hljs-string">'%Z'</span></code> accepts <code class="python hljs"><span class="hljs-string">'UTC/GMT'</span></code> and local timezone's code and returns timezone's name, <code class="python hljs"><span class="hljs-string">'UTC[±HH:MM]'</span></code> if timezone is nameless, or an empty string if datetime is naive.</strong></li> +<li><strong><code class="python hljs"><span class="hljs-string">'%z'</span></code> accepts <code class="python hljs"><span class="hljs-string">'±HH[:]MM'</span></code> and returns <code class="python hljs"><span class="hljs-string">'±HHMM'</span></code> or empty string if object is naive.</strong></li> +<li><strong><code class="python hljs"><span class="hljs-string">'%Z'</span></code> accepts <code class="python hljs"><span class="hljs-string">'UTC/GMT'</span></code> and local timezone's code and returns timezone's name, <code class="python hljs"><span class="hljs-string">'UTC[±HH:MM]'</span></code> if timezone is nameless, or an empty string if object is naive.</strong></li> </ul> <div><h3 id="arithmetics">Arithmetics</h3><pre><code class="python language-python apache hljs"><bool> = <D/T/DTn> > <D/T/DTn> <span class="hljs-comment"># Ignores time jumps (fold attribute). Also ==.</span> <bool> = <DTa> > <DTa> <span class="hljs-comment"># Ignores time jumps if they share tzinfo object.</span> @@ -605,7 +605,7 @@ shuffle(<list>) <span class="hljs-commen <ul> <li><strong>Function returns None if it doesn't encounter <code class="python hljs"><span class="hljs-string">'return <obj/exp>'</span></code> statement.</strong></li> -<li><strong>Before modifying a global variable from within the function run <code class="python hljs"><span class="hljs-string">'global <var_name>'</span></code>.</strong></li> +<li><strong>Run <code class="python hljs"><span class="hljs-string">'global <var_name>'</span></code> inside the function before assigning to global variable.</strong></li> <li><strong>Default values are evaluated when function is first encountered in the scope. Any mutation of a mutable default value will persist between invocations!</strong></li> </ul> <div><h3 id="functioncall">Function Call</h3><pre><code class="python language-python hljs"><obj> = <function>(<positional_args>) <span class="hljs-comment"># E.g. `func(0, 0)`.</span> @@ -2944,7 +2944,7 @@ $ deactivate <span class="hljs-comment"># Deactivates the active <footer> - <aside>March 30, 2025</aside> + <aside>April 1, 2025</aside> <a href="https://gto76.github.io" rel="author">Jure Šorn</a> </footer>