Sets are unordered collections of values that are great for removing duplicates, quick containment checks, and set operations. Table of contentsWhat are sets? Sets are like dictionaries without values Quick containment checks with sets Using set arithmetic Converting to a set for efficiency Checking for duplicates What are sets good for in Python? What are sets? Like lists, sets are collections of values: >>> fruits={"apples","strawberries","pears","apples"} But unlike lists, sets can't conta...| Python Morsels
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
Context managers power Python's with blocks. They sandwich a code block between enter code and exit code. They're most often used for reusing common cleanup/teardown functionality.| www.pythonmorsels.com
In Python, slicing looks like indexing with colons (:). You can slice a list (or any sequence) to get the first few items, the last few items, or all items in reverse.| www.pythonmorsels.com
In Python, truthiness is asking the question, what happens if I convert an object to a boolean. Every Python object is truthy by default. Truthiness in Python is about non-emptiness and non-zeroness.| www.pythonmorsels.com
Want to customize what "equality" means for your class instances in Python? Implement a __eq__ method! Make sure to return NotImplemented as appropriate though.| 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 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
The Python REPL is another name for Python's interactive Python interpreter, which accepts Python statements and immediately evaluates them.| www.pythonmorsels.com
Source code: Lib/decimal.py The decimal module provides support for fast correctly rounded decimal floating-point arithmetic. It offers several advantages over the float datatype: Decimal “is based...| Python documentation
Equality checks whether two objects represent the same value. Identity checks whether two variables point to the same object.| www.pythonmorsels.com
Source code: Lib/pickle.py The pickle module implements binary protocols for serializing and de-serializing a Python object structure. “Pickling” is the process whereby a Python object hierarchy is...| Python documentation
Source code: Lib/fractions.py The fractions module provides support for rational number arithmetic. A Fraction instance can be constructed from a pair of integers, from another rational number, or ...| Python documentation
Source code: Lib/typing.py This module provides runtime support for type hints. Consider the function below: The function surface_area_of_cube takes an argument expected to be an instance of float,...| Python documentation
>>>, The default Python prompt of the interactive shell. Often seen for code examples which can be executed interactively in the interpreter.,,..., Can refer to:- The default Python prompt of the i...| Python documentation
Source code: Lib/pathlib/ This module offers classes representing filesystem paths with semantics appropriate for different operating systems. Path classes are divided between pure paths, which pro...| Python documentation
Source code: Lib/os.py This module provides a portable way of using operating system dependent functionality. If you just want to read or write a file see open(), if you want to manipulate paths, s...| Python documentation
Source code: Lib/functools.py The functools module is for higher-order functions: functions that act on or return other functions. In general, any callable object can be treated as a function for t...| Python documentation
Objects, values and types: Objects are Python’s abstraction for data. All data in a Python program is represented by objects or by relations between objects. (In a sense, and in conformance to Von ...| Python documentation
Definitions for colloquial Python terminology (effectively an unofficial version of the Python glossary).| www.pythonmorsels.com