To use a function in Python, write the function name followed by parentheses. If the function accepts arguments, pass the arguments inside the parentheses.| www.pythonmorsels.com
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).| www.pythonmorsels.com
Want to turn a list of strings into a single string? You can use the string join method to join a list of strings together (concatenating them with a delimiter of your choice).| www.pythonmorsels.com
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.| www.pythonmorsels.com
In Python we care about the behavior of an object more than the type of an object. We say, "if it looks like a duck and walks like a duck, it's a duck." This idea is called duck typing.| www.pythonmorsels.com
It's best to avoid calling dunder methods. It's common to define dunder methods, but uncommon to call them directly.| www.pythonmorsels.com
Sets and dictionaries are powered by hashability. And hashable objects tend to be immutable.| www.pythonmorsels.com
Strings are used to store text-based data.| www.pythonmorsels.com
An explanation of all of Python's 100+ dunder methods and 50+ dunder attributes, including a summary of each one.| www.pythonmorsels.com
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.| www.pythonmorsels.com
Sequences are iterables that have a length. Sequences are ordered collections (they maintain the order of their contents). The most common sequences built-in to Python are string, tuple, and list.| www.pythonmorsels.com
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.| www.pythonmorsels.com
Lists are used to store and manipulate an ordered collection of things.| www.pythonmorsels.com
Any reversible iterable can be reversed using the built-in reversed function whereas Python's slicing syntax only works on sequences.| www.pythonmorsels.com
Python's built-in functions list includes 71 functions now! Which built-in functions are worth knowing about? And which functions should you learn later?| www.pythonmorsels.com
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.| www.pythonmorsels.com
Iterators are lazy iterables which power all iteration in Python. Iterators are the generic form of a generator-like object.| www.pythonmorsels.com
Python's dictionaries act as lookup tables which map keys to their values.| www.pythonmorsels.com
Classes are for coupling state (attributes) and functionality (methods). Calling a class returns an instance of that class. Class and "type" are synonyms in Python.| www.pythonmorsels.com
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.| www.pythonmorsels.com
Python's list comprehensions are special-purpose tools for taking an old iterable, looping over it, and making a new list out of it.| www.pythonmorsels.com
Python's "walrus operator" is used for assignment expressions. Assignment expressions are a way of embedding an assignment statement inside another line of code.| www.pythonmorsels.com
The Python REPL is another name for Python's interactive Python interpreter, which accepts Python statements and immediately evaluates them.| www.pythonmorsels.com
Python's variables are not buckets that contain objects; they're pointers. Assignment statements don't copy: they point a variable to a value (and multiple variables can "point" to the same value).| www.pythonmorsels.com
Equality checks whether two objects represent the same value. Identity checks whether two variables point to the same object.| www.pythonmorsels.com
List comprehensions make lists; generator expressions make generators. Generators are lazy single-use iterables which generate values as you loop over them.| www.pythonmorsels.com
An iterable is anything you're able to iterate over (iter-able). Iterables can be looped over and anything you can loop over is an iterable. Not every iterable is indexable or has a length.| www.pythonmorsels.com
Python's built-in next function will consume the next item from a given iterator.| www.pythonmorsels.com
You can set the value of a variable in Python by using the equals sign (=) to make an assignment statement.| www.pythonmorsels.com
While it is possible to make singleton objects in Python, the classic singleton design pattern doesn't always make a lot of sense.| www.pythonmorsels.com
When your code depends other Python libraries to run, you'll want to reach for pip and venv to install those third-party Python packages.| www.pythonmorsels.com