<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Summary on Arash Taher</title>
    <link>https://arashtaher.com/tags/summary/</link>
    <description>Recent content in Summary on Arash Taher</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 15 Oct 2026 13:06:57 +0200</lastBuildDate>
    <atom:link href="https://arashtaher.com/tags/summary/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Python Refresher 2026</title>
      <link>https://arashtaher.com/blog/python-refresher-2026/</link>
      <pubDate>Thu, 15 Oct 2026 13:06:57 +0200</pubDate>
      <guid>https://arashtaher.com/blog/python-refresher-2026/</guid>
      <description>&lt;p&gt;I haven&amp;rsquo;t done much programming with Python since version 2.7. Here&amp;rsquo;s a couple of notable examples and concepts that I&amp;rsquo;d like to keep as a reminder.&lt;/p&gt;&#xA;&lt;p&gt;Here are the highlights for me after going through &lt;a href=&#34;https://learnxinyminutes.com/python/&#34;&gt;Learn X in Y minutes&lt;/a&gt; and &lt;a href=&#34;https://gto76.github.io/python-cheatsheet/&#34;&gt;Python Cheatsheet&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;## 1. Primitive Datatypes and Operators&#xA;&#xA;# True and False are actually 1 and 0 but with different keywords&#xA;True + True  # =&amp;gt; 2&#xA;0 == False   # =&amp;gt; True&#xA;&#xA;1 &amp;lt; 2 &amp;lt; 3  # =&amp;gt; True&#xA;&#xA;&amp;quot;Hello &amp;quot; &amp;quot;world!&amp;quot;    # =&amp;gt; &amp;quot;Hello world!&amp;quot;&#xA;&#xA;# f-strings&#xA;name = &amp;quot;Reiko&amp;quot;&#xA;f&amp;quot;{name} is {len(name)} characters long.&amp;quot;&#xA;&#xA;# None is an object. Use &amp;quot;is&amp;quot;, and NOT &amp;quot;==&amp;quot; to check for equality of object identity.&#xA;None is None   # =&amp;gt; True&#xA;&#xA;## 2. Variables and Collections&#xA;input_string_var = input(&amp;quot;Enter some data: &amp;quot;)&#xA;&#xA;some_unknown_var  # Raises a NameError&#xA;&#xA;## Lists&#xA;&#xA;li = [1, 2, 3]&#xA;li[::-1]  # [3, 2, 1]&#xA;li2 = li[:] # Shallow copy&#xA;li.index(5)  # Raises a ValueError&#xA;1 in li  # =&amp;gt; True&#xA;&#xA;## Tuples&#xA;&#xA;# Tuples are like lists but are immutable.&#xA;tup = (1, 2, 3)&#xA;tup[0] = 3  # Raises a TypeError&#xA;type((1))   # =&amp;gt; &amp;lt;class &#39;int&#39;&amp;gt;&#xA;type((1,))  # =&amp;gt; &amp;lt;class &#39;tuple&#39;&amp;gt;&#xA;a, *b, c = 1, 2, 3, 4  # b is now [2, 3]&#xA;&#xA;## Dictionaries&#xA;&#xA;filled_dict = {&amp;quot;one&amp;quot;: 1, &amp;quot;two&amp;quot;: 2, &amp;quot;three&amp;quot;: 3}&#xA;# Keys have to be of immutable types for quick look-up: ints, floats, strings, tuples&#xA;invalid_dict = {[1,2,3]: &amp;quot;123&amp;quot;}  # =&amp;gt; Yield a TypeError: unhashable type: &#39;list&#39;&#xA;# Keys and values insert order is preserved in Python 3.7+&#xA;list(filled_dict.keys())  # [&amp;quot;three&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;one&amp;quot;] in Python &amp;lt;3.7&#xA;&#xA;filled_dict[&amp;quot;four&amp;quot;]  # KeyError&#xA;filled_dict.get(&amp;quot;four&amp;quot;)     # =&amp;gt; None&#xA;&#xA;{&amp;quot;a&amp;quot;: 1, **{&amp;quot;a&amp;quot;: 2}}  # =&amp;gt; {&#39;a&#39;: 2} unpacking options&#xA;&#xA;## Sets&#xA;&#xA;invalid_set = {[1], 1}  # =&amp;gt; Raises a TypeError: unhashable type: &#39;list&#39;&#xA;valid_set = {(1,), 1}&#xA;# Operations: &amp;amp; | - ^ &amp;gt;= &amp;lt;=&#xA;&#xA;## 3. Control Flow and Iterables&#xA;&#xA;# match&#xA;command = &amp;quot;run&amp;quot;&#xA;match command:&#xA;    case &amp;quot;run&amp;quot;: print(&amp;quot;The robot started to run 🏃‍♂️&amp;quot;)&#xA;    case _:  print(&amp;quot;Invalid command ❌&amp;quot;)&#xA;    &#xA;# enumerate&#xA;animals = [&amp;quot;dog&amp;quot;, &amp;quot;cat&amp;quot;, &amp;quot;mouse&amp;quot;]&#xA;for i, value in enumerate(animals):&#xA;    print(i, value)&#xA;    &#xA;# Iterables&#xA;filled_dict = {&amp;quot;one&amp;quot;: 1, &amp;quot;two&amp;quot;: 2, &amp;quot;three&amp;quot;: 3}&#xA;our_iterable = filled_dict.keys()&#xA;our_iterable[1]  # Raises a TypeError&#xA;# An iterable is an object that knows how to create an iterator.&#xA;our_iterator = iter(our_iterable)&#xA;next(our_iterator)  # =&amp;gt; &amp;quot;one&amp;quot;... and then -&amp;gt;&#xA;next(our_iterator)  # Raises StopIteration&#xA;&#xA;## 4. Functions&#xA;&#xA;# Splat operator * and splatty-splat **&#xA;def all_the_args(*args, **kwargs): pass # positional arguments (tuples) and keyword arguments&#xA;&#xA;# Closures in nested functions:&#xA;def create_avg():&#xA;    total = 0&#xA;    count = 0&#xA;    def avg(n):&#xA;        # Reading an outer variable works without declaration, but any assignment requires nonlocal (or global)&#xA;        # Otherwise: `UnboundLocalError: cannot access local variable &#39;total&#39; where it is not associated with a value`&#xA;        nonlocal total, count&#xA;        total += n&#xA;        count += 1&#xA;        return total/count&#xA;    return avg&#xA;&#xA;avg = create_avg()&#xA;avg(3)  # =&amp;gt; 3.0&#xA;avg(5)  # (3+5)/2 =&amp;gt; 4.0&#xA;&#xA;list(map(max, [1, 2, 3], [4, 2, 1, 6]))  # =&amp;gt; [4, 2, 3]&#xA;&#xA;# Set comprehension&#xA;{x for x in &amp;quot;abcddeef&amp;quot; if x not in &amp;quot;abc&amp;quot;}  # =&amp;gt; {&#39;d&#39;, &#39;e&#39;, &#39;f&#39;}&#xA;&#xA;## 5. Modules&#xA;&#xA;# Find out which functions and attributes are defined in a module.&#xA;import math&#xA;dir(math)&#xA;&#xA;## Classes&#xA;&#xA;class Human:&#xA;    # Class attribute&#xA;    species = &amp;quot;H. sapiens&amp;quot;&#xA;    # Methods, objects or attributes like: __init__, __repr__ etc. are called special methods (or dunder methods)&#xA;    def __init__(self, name):&#xA;        self.name = name&#xA;        self._age = 0&#xA;    @classmethod&#xA;    def get_species(cls):&#xA;        return cls.species&#xA;    @staticmethod&#xA;    def grunt():&#xA;        return &amp;quot;*grunt*&amp;quot;&#xA;    @property&#xA;    def age(self):&#xA;        return self._age&#xA;    @age.setter&#xA;    def age(self, age):&#xA;        self._age = age&#xA;    @age.deleter&#xA;    def age(self):&#xA;        del self._age&#xA;&#xA;i = Human(name=&amp;quot;Ian&amp;quot;)&#xA;i.say(i.age)&#xA;del i.age&#xA;# i.age # =&amp;gt; this would raise an AttributeError&#xA;&#xA;# Inheritance&#xA;class Superhero(Human): pass&#xA;&#xA;if isinstance(sup, Human): print(&amp;quot;I am human&amp;quot;)&#xA;if type(sup) is Superhero: print(&amp;quot;I am a superhero&amp;quot;)&#xA;&#xA;# Get the &amp;quot;Method Resolution Order&amp;quot; used by both getattr() and super()&#xA;print(Superhero.__mro__) # =&amp;gt; (&amp;lt;class &#39;__main__.Superhero&#39;&amp;gt;, &amp;lt;class &#39;human.Human&#39;&amp;gt;, &amp;lt;class &#39;object&#39;&amp;gt;)&#xA;&#xA;## 7. Advanced&#xA;&#xA;# Generator comprehensions as well.&#xA;values = (-x for x in [1,2,3]) # &amp;lt;class &#39;generator&#39;&amp;gt;&#xA;for x in values: print(x)  # prints -1 -2 -3&#xA;&#xA;# Decorators&#xA;from functools import wraps&#xA;&#xA;def log_function(func):&#xA;    @wraps(func)  # this ensures docstring, function name, arguments list, etc. are all copied&#xA;                  # to the wrapped function - instead of being replaced with wrapper&#39;s info&#xA;    def wrapper(*args, **kwargs):&#xA;        print(&amp;quot;Entering function&amp;quot;, func.__name__)&#xA;        result = func(*args, **kwargs)&#xA;        print(&amp;quot;Exiting function&amp;quot;, func.__name__)&#xA;        return result&#xA;    return wrapper&#xA;&#xA;@log_function&#xA;def my_function(x,y):&#xA;    &amp;quot;&amp;quot;&amp;quot;Adds two numbers together.&amp;quot;&amp;quot;&amp;quot;&#xA;    return x+y&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Methods that are decorated with &lt;code&gt;@staticmethod&lt;/code&gt; receive neither &lt;code&gt;self&lt;/code&gt; nor &lt;code&gt;cls&lt;/code&gt; arg.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;__repr__&lt;/code&gt; should be unambiguous string representation of an object. Ideally return a string that looks like valid Python code capable of recreating the object&lt;/li&gt;&#xA;&lt;/ul&gt;</description>
    </item>
  </channel>
</rss>
