<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>PyVideo.org - Python Morsels</title><link href="https://pyvideo.org/" rel="alternate"></link><link href="https://pyvideo.org/feeds/event_python-morsels.atom.xml" rel="self"></link><id>https://pyvideo.org/</id><updated>2022-10-10T00:00:00+00:00</updated><subtitle></subtitle><entry><title>Unindenting multi-line strings in Python</title><link href="https://pyvideo.org/python-morsels/dedent.html" rel="alternate"></link><published>2022-10-10T00:00:00+00:00</published><updated>2022-10-10T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2022-10-10:/python-morsels/dedent.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Need a multi-line string but don't want to include a big block of manually dedented text in your Python code? Use textwrap.dedent!&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Strings"></category></entry><entry><title>Reading binary files in Python</title><link href="https://pyvideo.org/python-morsels/reading-binary-files-in-python.html" rel="alternate"></link><published>2022-05-16T00:00:00+00:00</published><updated>2022-05-16T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2022-05-16:/python-morsels/reading-binary-files-in-python.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;How can you read binary files in Python? And how can you read very large binary files in small chunks?&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Files"></category></entry><entry><title>Unicode character encodings</title><link href="https://pyvideo.org/python-morsels/unicode-character-encodings-in-python.html" rel="alternate"></link><published>2022-05-02T00:00:00+00:00</published><updated>2022-05-02T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2022-05-02:/python-morsels/unicode-character-encodings-in-python.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;When working with text files in Python, it's considered a best practice to specify the character encoding that you're working with.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Files"></category></entry><entry><title>What is an iterator?</title><link href="https://pyvideo.org/python-morsels/what-is-an-iterator.html" rel="alternate"></link><published>2022-03-14T00:00:00+00:00</published><updated>2022-03-14T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2022-03-14:/python-morsels/what-is-an-iterator.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Iterators are lazy iterables which power all iteration in Python. Iterators are the generic form of a generator-like object.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Generator Function"></category></entry><entry><title>How to create a generator function</title><link href="https://pyvideo.org/python-morsels/how-to-create-a-generator-function.html" rel="alternate"></link><published>2022-03-07T00:00:00+00:00</published><updated>2022-03-07T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2022-03-07:/python-morsels/how-to-create-a-generator-function.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Have a function that returns a list? You may be able to turn it into a generator function by replacing the &lt;cite&gt;append&lt;/cite&gt; calls with &lt;cite&gt;yield&lt;/cite&gt; statements.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Generator Function"></category></entry><entry><title>What is a generator function?</title><link href="https://pyvideo.org/python-morsels/what-is-a-generator-function.html" rel="alternate"></link><published>2022-02-28T00:00:00+00:00</published><updated>2022-02-28T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2022-02-28:/python-morsels/what-is-a-generator-function.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;When you call a generator function it doesn't actually run the function; instead it returns a generator object.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Generator Function"></category></entry><entry><title>How to read a traceback in Python</title><link href="https://pyvideo.org/python-morsels/reading-tracebacks-in-python.html" rel="alternate"></link><published>2022-01-03T00:00:00+00:00</published><updated>2022-01-03T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2022-01-03:/python-morsels/reading-tracebacks-in-python.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;When exceptions go unhandled, Python prints a traceback. Tracebacks are &lt;strong&gt;read from the bottom upward&lt;/strong&gt;. The last line describes &lt;em&gt;what&lt;/em&gt; happened and lines above describe &lt;em&gt;where&lt;/em&gt; it happened.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Exception"></category></entry><entry><title>Modules are cached</title><link href="https://pyvideo.org/python-morsels/modules-are-cached.html" rel="alternate"></link><published>2021-11-01T00:00:00+00:00</published><updated>2021-11-01T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-11-01:/python-morsels/modules-are-cached.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;When re-importing a module Python will use the cached version of your module (instead of reevaluating your code). To refresh a module while in the Python REPL, it's best to exit and start a new REPL.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Modules"></category></entry><entry><title>How to write to a file in Python</title><link href="https://pyvideo.org/python-morsels/creating-and-writing-file-python.html" rel="alternate"></link><published>2021-10-18T00:00:00+00:00</published><updated>2021-10-18T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-10-18:/python-morsels/creating-and-writing-file-python.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;To write to a file in Python, you can use the built-in &lt;cite&gt;open&lt;/cite&gt; function, specifying a mode of &lt;cite&gt;w&lt;/cite&gt; or &lt;cite&gt;wt&lt;/cite&gt; and then use the &lt;cite&gt;write&lt;/cite&gt; method on the file object.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Files"></category></entry><entry><title>Read a file line-by-line in Python</title><link href="https://pyvideo.org/python-morsels/reading-files-line-line.html" rel="alternate"></link><published>2021-10-11T00:00:00+00:00</published><updated>2021-10-11T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-10-11:/python-morsels/reading-files-line-line.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;When Python reads a file line-by-line, it doesn't store the whole file in memory all at once. Files are lazy iterables, and as we loop over a file object, we'll get lines from that file.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Files"></category></entry><entry><title>How to read from a text file</title><link href="https://pyvideo.org/python-morsels/how-read-text-file.html" rel="alternate"></link><published>2021-10-04T00:00:00+00:00</published><updated>2021-10-04T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-10-04:/python-morsels/how-read-text-file.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;To work with a text file in Python, you can use the built-in open function, which gives you back a file object. Reading from and writing to text files is an important skill.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Files"></category></entry><entry><title>Defining a main function in Python</title><link href="https://pyvideo.org/python-morsels/making-main-function-python.html" rel="alternate"></link><published>2021-09-27T00:00:00+00:00</published><updated>2021-09-27T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-09-27:/python-morsels/making-main-function-python.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;How can you setup a main function in Python? And should you? Python doesn't know about main functions, but there's nothing stopping us from defining a function called main that we only call when running from the command-line.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Command Line Interfaces"></category></entry><entry><title>Importing a module runs code</title><link href="https://pyvideo.org/python-morsels/importing-module-runs-code.html" rel="alternate"></link><published>2021-09-13T00:00:00+00:00</published><updated>2021-09-13T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-09-13:/python-morsels/importing-module-runs-code.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;When Python imports a module, it runs all the code in that module.
So if your Python file is meant to be imported as a module, be careful not to put side effects at the top-level of your &lt;cite&gt;.py&lt;/cite&gt; file.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Modules"></category></entry><entry><title>Parsing command-line arguments in Python</title><link href="https://pyvideo.org/python-morsels/parsing-command-line-arguments-python.html" rel="alternate"></link><published>2021-09-06T00:00:00+00:00</published><updated>2021-09-06T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-09-06:/python-morsels/parsing-command-line-arguments-python.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;If you're trying to make a friendly command-line interface in Python, instead of manually parsing sys.argv you should probably use Python's argparse module.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Command Line Interfaces"></category></entry><entry><title>Accessing command-line arguments in Python</title><link href="https://pyvideo.org/python-morsels/accessing-command-line-arguments-python.html" rel="alternate"></link><published>2021-08-30T00:00:00+00:00</published><updated>2021-08-30T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-08-30:/python-morsels/accessing-command-line-arguments-python.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;If you need to make a very simple command-line interface and it doesn't need to be friendly, you can read sys.argv to manually process the arguments coming into your program.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Command Line Interfaces"></category></entry><entry><title>Python's walrus operator</title><link href="https://pyvideo.org/python-morsels/using-walrus-operator.html" rel="alternate"></link><published>2021-08-16T00:00:00+00:00</published><updated>2021-08-16T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-08-16:/python-morsels/using-walrus-operator.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Python's &amp;quot;walrus operator&amp;quot; is used for assignment expressions. Assignment expressions are a way of embedding an assignment statement inside another line of code.&lt;/p&gt;
</content><category term="Python Morsels"></category></entry><entry><title>Customizing what happens when you assign an attribute</title><link href="https://pyvideo.org/python-morsels/customizing-what-happens-when-you-assign-attribute.html" rel="alternate"></link><published>2021-08-08T00:00:00+00:00</published><updated>2021-08-08T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-08-08:/python-morsels/customizing-what-happens-when-you-assign-attribute.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Want to customize what happens when you assign to a specific attribute on your class instances? You can use a property with a setter.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Properties"></category></entry><entry><title>Making a read-only attribute</title><link href="https://pyvideo.org/python-morsels/making-read-only-attribute.html" rel="alternate"></link><published>2021-08-03T00:00:00+00:00</published><updated>2021-08-03T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-08-03:/python-morsels/making-read-only-attribute.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;If you need to make a read-only attribute in Python, you can turn your attribute into a property that delegates to an attribute with almost the same name (but with an underscore prefix).&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Properties"></category></entry><entry><title>Python's map and filter functions</title><link href="https://pyvideo.org/python-morsels/map-and-filter-python.html" rel="alternate"></link><published>2021-07-26T00:00:00+00:00</published><updated>2021-07-26T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-07-26:/python-morsels/map-and-filter-python.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;How do Python's built-in map and filter functions work? And should you use them or should you use list comprehensions or generator expressions instead?&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Generator Expression"></category></entry><entry><title>How to write a generator expression</title><link href="https://pyvideo.org/python-morsels/how-write-generator-expression.html" rel="alternate"></link><published>2021-07-13T00:00:00+00:00</published><updated>2021-07-13T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-07-13:/python-morsels/how-write-generator-expression.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;List comprehensions make lists; generator expressions make generators. Generators are lazy single-use iterables which generate values as you loop over them.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Generator Expression"></category></entry><entry><title>How to make a decorator</title><link href="https://pyvideo.org/python-morsels/make-decorator.html" rel="alternate"></link><published>2021-06-14T00:00:00+00:00</published><updated>2021-06-14T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-06-14:/python-morsels/make-decorator.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;A decorator is a function that accepts a function and returns a function. That's true for function decorators at least.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Decorators"></category></entry><entry><title>What is a decorator?</title><link href="https://pyvideo.org/python-morsels/what-is-a-decorator.html" rel="alternate"></link><published>2021-06-09T00:00:00+00:00</published><updated>2021-06-09T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-06-09:/python-morsels/what-is-a-decorator.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;A decorator is a callable (usually a function though sometimes a class) that accepts either a function or a class and returns a new function or class that wraps around the original one.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Decorators"></category></entry><entry><title>Passing functions as arguments to other functions</title><link href="https://pyvideo.org/python-morsels/passing-functions-arguments-other-functions.html" rel="alternate"></link><published>2021-06-03T00:00:00+00:00</published><updated>2021-06-03T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-06-03:/python-morsels/passing-functions-arguments-other-functions.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;In Python, you can pass functions (as an argument) to another function. Some of Python's built-in functions actually expect functions to be given as one or more of their arguments to call them later.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Decorators"></category></entry><entry><title>The meaning of "callable" in Python</title><link href="https://pyvideo.org/python-morsels/callables.html" rel="alternate"></link><published>2021-05-28T00:00:00+00:00</published><updated>2021-05-28T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-05-28:/python-morsels/callables.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;A callable is a function-like object, meaning it's something that behaves like a function. The primary types of callables in Python are functions and classes, though other callable objects do exist.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Decorators"></category></entry><entry><title>Turning a for loop into a list comprehension</title><link href="https://pyvideo.org/python-morsels/turning-loop-list-comprehension.html" rel="alternate"></link><published>2021-05-18T00:00:00+00:00</published><updated>2021-05-18T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-05-18:/python-morsels/turning-loop-list-comprehension.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;If you're new to comprehensions, I recommend copy-pasting your way from a loop to comprehension to anchor your existing understanding of &lt;cite&gt;for&lt;/cite&gt; loops with your new knowledge of comprehensions.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Comprehensions"></category></entry><entry><title>Breaking up long lines of code in Python</title><link href="https://pyvideo.org/python-morsels/breaking-long-lines-code-python.html" rel="alternate"></link><published>2021-05-06T00:00:00+00:00</published><updated>2021-05-06T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-05-06:/python-morsels/breaking-long-lines-code-python.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Have a long line of code? If you don't have brackets or braces on your line yet, you can add parentheses wherever you'd like and put line breaks within them. We call this &amp;quot;implicit line continuation&amp;quot;.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Fundamentals"></category></entry><entry><title>List comprehensions in Python</title><link href="https://pyvideo.org/python-morsels/what-are-list-comprehensions.html" rel="alternate"></link><published>2021-04-28T00:00:00+00:00</published><updated>2021-04-28T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-04-28:/python-morsels/what-are-list-comprehensions.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Python's list comprehensions are special-purpose tools for taking an old iterable, looping over it, and making a new list out of it.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Comprehensions"></category></entry><entry><title>4 ways to import a module in Python</title><link href="https://pyvideo.org/python-morsels/4-ways-import-module-python.html" rel="alternate"></link><published>2021-04-21T00:00:00+00:00</published><updated>2021-04-21T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-04-21:/python-morsels/4-ways-import-module-python.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;In Python you can import specific variables from a module, you can import the whole module, and you can also rename variables while importing. When should you use each of these import styles?&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Modules"></category></entry><entry><title>Making an auto-updating attribute</title><link href="https://pyvideo.org/python-morsels/making-auto-updating-attribute.html" rel="alternate"></link><published>2021-04-20T00:00:00+00:00</published><updated>2021-04-20T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-04-20:/python-morsels/making-auto-updating-attribute.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;We don't use getter methods in Python, instead we use the property decorator to make make automatically updating attributes. Properties allow us to customize what happens when you access an attribute.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Properties"></category></entry><entry><title>Tuple unpacking</title><link href="https://pyvideo.org/python-morsels/tuple-unpacking.html" rel="alternate"></link><published>2021-03-25T00:00:00+00:00</published><updated>2021-03-25T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-03-25:/python-morsels/tuple-unpacking.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Instead of using hard-coded indices to get tuple elements, use tuple unpacking to give descriptive names to each item. Important items should have a name instead of a number.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Tuple Unpacking"></category></entry><entry><title>Importing a module in Python</title><link href="https://pyvideo.org/python-morsels/importing-module.html" rel="alternate"></link><published>2021-03-18T00:00:00+00:00</published><updated>2021-03-18T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-03-18:/python-morsels/importing-module.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;When you import a module in Python, you'll get access to a module object with attributes representing each of the variables in that module. Python comes bundled with a bunch of modules.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Modules"></category></entry><entry><title>Inheriting one class from another</title><link href="https://pyvideo.org/python-morsels/inheriting-one-class-another.html" rel="alternate"></link><published>2021-03-04T00:00:00+00:00</published><updated>2021-03-04T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-03-04:/python-morsels/inheriting-one-class-another.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;To inherit your class from another class, put parentheses after the class name and list parent classes. We allow multiple inheritance in Python, but we usually prefer single class inheritance.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Classes"></category><category term="Inheritance"></category></entry><entry><title>__init__ in Python</title><link href="https://pyvideo.org/python-morsels/what-is-init.html" rel="alternate"></link><published>2021-02-11T00:00:00+00:00</published><updated>2021-02-11T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-02-11:/python-morsels/what-is-init.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;The &lt;cite&gt;__init__&lt;/cite&gt; method is used to initialize a class. The initializer method accepts self (the class instance) along with any arguments the class accepts and then performs initialization steps.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Classes"></category></entry><entry><title>Customizing the string representation of your objects</title><link href="https://pyvideo.org/python-morsels/customizing-string-representation-your-objects.html" rel="alternate"></link><published>2021-01-22T00:00:00+00:00</published><updated>2021-01-22T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-01-22:/python-morsels/customizing-string-representation-your-objects.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;You'll almost always just want to customize one of Python's two string representations (&lt;cite&gt;repr&lt;/cite&gt;, the programmer readable-one). The human-readable representation (&lt;cite&gt;str&lt;/cite&gt;) delegates to &lt;cite&gt;repr&lt;/cite&gt; by default.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Dunder Methods"></category></entry><entry><title>Dunder methods in Python</title><link href="https://pyvideo.org/python-morsels/what-are-dunder-methods.html" rel="alternate"></link><published>2021-01-05T00:00:00+00:00</published><updated>2021-01-05T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2021-01-05:/python-morsels/what-are-dunder-methods.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Dunder methods power most operators in Python as well as some of the built-in functions. Dunder methods are a contract between the person who made a class and Python itself.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Dunder Methods"></category></entry><entry><title>Python's 2 different string representations</title><link href="https://pyvideo.org/python-morsels/pythons-two-different-string-representations.html" rel="alternate"></link><published>2020-12-30T00:00:00+00:00</published><updated>2020-12-30T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2020-12-30:/python-morsels/pythons-two-different-string-representations.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;In Python, we have two different string representations: the human-readable string representation and the programmer-readable string representation (called repr and str respectively).&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Strings"></category></entry><entry><title>Python's self</title><link href="https://pyvideo.org/python-morsels/what-is-self.html" rel="alternate"></link><published>2020-12-28T00:00:00+00:00</published><updated>2020-12-28T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2020-12-28:/python-morsels/what-is-self.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Python's &lt;cite&gt;self&lt;/cite&gt; is really just a variable that points to the current instance of our class. Every method you define must accept &lt;cite&gt;self&lt;/cite&gt; as its first argument.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Classes"></category></entry><entry><title>Classes are everywhere</title><link href="https://pyvideo.org/python-morsels/classes-are-everywhere.html" rel="alternate"></link><published>2020-12-22T00:00:00+00:00</published><updated>2020-12-22T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2020-12-22:/python-morsels/classes-are-everywhere.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Even if you never make your class, you will certainly use classes. A lot of the built-in functions in Python are classes too. Anything that has a type has a class.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Classes"></category></entry><entry><title>What is a class?</title><link href="https://pyvideo.org/python-morsels/what-is-a-class.html" rel="alternate"></link><published>2020-12-09T00:00:00+00:00</published><updated>2020-12-09T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2020-12-09:/python-morsels/what-is-a-class.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Classes are for coupling state (attributes) and functionality (methods). Calling a class returns an instance of that class. Class and &amp;quot;type&amp;quot; are synonyms in Python.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Classes"></category></entry><entry><title>Accepting arbitrary keyword arguments in Python</title><link href="https://pyvideo.org/python-morsels/accepting-arbitrary-keyword-arguments.html" rel="alternate"></link><published>2020-12-04T00:00:00+00:00</published><updated>2020-12-04T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2020-12-04:/python-morsels/accepting-arbitrary-keyword-arguments.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Ever seen &lt;cite&gt;**kwargs&lt;/cite&gt; in a function definition? There's nothing special about the name &amp;quot;kwargs&amp;quot;: it's the &lt;cite&gt;**&lt;/cite&gt; that's special. You can use Python's &lt;cite&gt;**&lt;/cite&gt; operator to define a function that accepts arbitrary keyword arguments.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Functions"></category><category term="Asterisks"></category></entry><entry><title>Keyword-only function arguments</title><link href="https://pyvideo.org/python-morsels/keyword-only-function-arguments.html" rel="alternate"></link><published>2020-11-30T00:00:00+00:00</published><updated>2020-11-30T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2020-11-30:/python-morsels/keyword-only-function-arguments.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;If you see a function that has an asterisk (&lt;cite&gt;*&lt;/cite&gt;) on its own with a comma after it, every argument after that point is a keyword-only argument (an argument which can only be specified by its name).&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Functions"></category><category term="Asterisks"></category></entry><entry><title>Accepting any number of arguments to a function</title><link href="https://pyvideo.org/python-morsels/accepting-any-number-arguments-function.html" rel="alternate"></link><published>2020-11-18T00:00:00+00:00</published><updated>2020-11-18T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2020-11-18:/python-morsels/accepting-any-number-arguments-function.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;To make a function that accepts any number of arguments, you can use the &lt;cite&gt;*&lt;/cite&gt; operator and then some variable name when defining your function. Some of Python's built-in functions work this way.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Functions"></category><category term="Asterisks"></category></entry><entry><title>How to make a function</title><link href="https://pyvideo.org/python-morsels/making-a-function.html" rel="alternate"></link><published>2020-11-16T00:00:00+00:00</published><updated>2020-11-16T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2020-11-16:/python-morsels/making-a-function.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;To define a function in Python, use the def keyword with the function name and any accepted arguments (in parentheses). Functions have inputs (arguments) and an optional output (the return value).&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Functions"></category></entry><entry><title>Positional vs keyword arguments</title><link href="https://pyvideo.org/python-morsels/positional-vs-keyword-arguments.html" rel="alternate"></link><published>2020-11-12T00:00:00+00:00</published><updated>2020-11-12T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2020-11-12:/python-morsels/positional-vs-keyword-arguments.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;When you're working with named arguments (a.k.a. keyword arguments) it's the argument name that matters. When you're working with positional arguments, it's the position matters (but not the name).&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Functions"></category></entry><entry><title>How to call a function in Python</title><link href="https://pyvideo.org/python-morsels/calling-a-function.html" rel="alternate"></link><published>2020-11-11T00:00:00+00:00</published><updated>2020-11-11T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2020-11-11:/python-morsels/calling-a-function.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;To use a function in Python, write the function name followed by parentheses. If the function accepts arguments, pass the arguments inside the parentheses.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Functions"></category></entry><entry><title>Looping over multiple iterables at once</title><link href="https://pyvideo.org/python-morsels/looping-over-multiple-iterables.html" rel="alternate"></link><published>2020-10-13T00:00:00+00:00</published><updated>2020-10-13T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2020-10-13:/python-morsels/looping-over-multiple-iterables.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Need to loop over two (or more) iterables at the same time? Don't use range. Don't use enumerate. Use the built-in zip function. As you loop over zip you'll get the n-th item from each iterable.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Looping"></category></entry><entry><title>Looping with indexes</title><link href="https://pyvideo.org/python-morsels/looping-with-indexes.html" rel="alternate"></link><published>2020-10-08T00:00:00+00:00</published><updated>2020-10-08T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2020-10-08:/python-morsels/looping-with-indexes.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Python's built-in enumerate function is the preferred way to loop while counting upward at the same time. You'll almost always see tuple unpacking used whenever enumerate is used.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Looping"></category></entry><entry><title>What is an iterable?</title><link href="https://pyvideo.org/python-morsels/iterable.html" rel="alternate"></link><published>2020-10-06T00:00:00+00:00</published><updated>2020-10-06T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2020-10-06:/python-morsels/iterable.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;An iterable is anything you're able to iterate over (iter-&lt;em&gt;able&lt;/em&gt;). Iterables can be looped over and anything you can loop over is an iterable. Not every iterable is indexable or has a length.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Looping"></category></entry><entry><title>Writing a for loop</title><link href="https://pyvideo.org/python-morsels/writing-a-for-loop.html" rel="alternate"></link><published>2020-09-29T00:00:00+00:00</published><updated>2020-09-29T00:00:00+00:00</updated><author><name>Trey Hunner</name></author><id>tag:pyvideo.org,2020-09-29:/python-morsels/writing-a-for-loop.html</id><content type="html">&lt;h3&gt;Description&lt;/h3&gt;&lt;p&gt;Unlike traditional C-style for loops, Python's for loops don't have indexes. It's considered a best practice to avoid reaching for indexes unless you really need them.&lt;/p&gt;
</content><category term="Python Morsels"></category><category term="Looping"></category></entry></feed>