<li><strong>By default, decimal characters, alphanumerics and whitespaces from all alphabets are matched unless <codeclass="python hljs"><spanclass="hljs-string">'flags=re.ASCII'</span></code> argument is used.</strong></li>
<li><strong>As shown below, it restricts special sequence matches to <codeclass="python hljs"><spanclass="hljs-string">'[\x00-\x7f]'</span></code> and prevents <codeclass="python hljs"><spanclass="hljs-string">'\s'</span></code> from accepting <codeclass="python hljs"><spanclass="hljs-string">'[\x1c\x1d\x1e\x1f]'</span></code>.</strong></li>
<li><strong>As shown below, it restricts special sequence matches to the first 128 characters and prevents <codeclass="python hljs"><spanclass="hljs-string">'\s'</span></code> from accepting <codeclass="python hljs"><spanclass="hljs-string">'[\x1c\x1d\x1e\x1f]'</span></code>.</strong></li>
<li><strong>Use a capital letter for negation.</strong></li>
<div><h3id="strings">Strings</h3><p><strong><codeclass="python hljs"><spanclass="hljs-string">'!r'</span></code> calls object's <ahref="#class">repr()</a> method, instead of <ahref="#class">str()</a>, to get a string.</strong></p><pre><codeclass="python language-python hljs">{<spanclass="hljs-string">'abcde'</span>!r:<spanclass="hljs-number">10</span>} <spanclass="hljs-comment"># "'abcde' "</span>
<ul>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'{<el>:{<str/int/float>}[...]}'</span></code> to set options dynamically.</strong></li>
<li><strong>Adding <codeclass="python hljs"><spanclass="hljs-string">'!r'</span></code> before the colon converts object to string by calling its <ahref="#class">repr()</a> method.</strong></li>
<li><strong>Names of their required methods are stored in <codeclass="python hljs"><spanclass="hljs-string">'<abc>.__abstractmethods__'</span></code>.</strong></li>
</ul>
<div><h2id="enum"><ahref="#enum"name="enum">#</a>Enum</h2><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> enum <spanclass="hljs-keyword">import</span> Enum, auto
<conn>.rollback() <spanclass="hljs-comment"># Discards all changes since the last commit.</span>
</code></pre></div>
<div><h4id="or">Or:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">with</span><conn>: <spanclass="hljs-comment"># Exits block with commit() or rollback(),</span>
<div><h4id="or">Or:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">with</span><conn>: <spanclass="hljs-comment"># Exits the block with commit() or rollback(),</span>
<conn>.execute(<spanclass="hljs-string">'<query>'</span>) <spanclass="hljs-comment"># depending on whether an exception occurred.</span>
</ul></div></div><div><h4id="integertypesuseacapitalletterforunsignedtypeminimumandstandardsizesareinbrackets">Integer types. Use a capital letter for unsigned type. Minimum and standard sizes are in brackets:</h4><ul>
<div><h3id="thread">Thread</h3><pre><codeclass="python language-python hljs"><Thread> = Thread(target=<function>) <spanclass="hljs-comment"># Use `args=<collection>` to set arguments.</span>
<div><h3id="thread">Thread</h3><pre><codeclass="python language-python hljs"><Thread> = Thread(target=<function>) <spanclass="hljs-comment"># Use `args=<collection>` to set the arguments.</span>
<Thread>.start() <spanclass="hljs-comment"># Starts the thread.</span>
<bool> = <Thread>.is_alive() <spanclass="hljs-comment"># Checks if thread has finished executing.</span>
<Thread>.join() <spanclass="hljs-comment"># Waits for thread to finish.</span>
<bool> = <Thread>.is_alive() <spanclass="hljs-comment"># Checks if the thread has finished executing.</span>
<Thread>.join() <spanclass="hljs-comment"># Waits for the thread to finish.</span>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'daemon=True'</span></code>, or the program will not be able to exit while the thread is alive.</strong></li>
</ul>
<div><h3id="lock">Lock</h3><pre><codeclass="python language-python hljs"><lock> = RLock() <spanclass="hljs-comment"># Lock that can only be released by the owner.</span>
<lock>.acquire() <spanclass="hljs-comment"># Waits for lock to be available.</span>
<lock>.release() <spanclass="hljs-comment"># Makes lock available again.</span>
<lock>.acquire() <spanclass="hljs-comment"># Waits for the lock to be available.</span>
<lock>.release() <spanclass="hljs-comment"># Makes the lock available again.</span>
<div><h4id="or-1">Or:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">with</span><lock>: <spanclass="hljs-comment"># Enters the block by calling acquire(),</span>
... <spanclass="hljs-comment"># and exits it with release().</span>
</code></pre></div>
<div><h3id="semaphoreeventbarrier">Semaphore, Event, Barrier</h3><pre><codeclass="python language-python hljs"><Semaphore> = Semaphore(value=<spanclass="hljs-number">1</span>) <spanclass="hljs-comment"># Lock that can be acquired by 'value' threads.</span>