AC
AnkiCollab
AnkiCollab
Sign in
Explore Decks
Helpful
Join Discord
Download Add-on
Documentation
Support Us
Notes in
Week 4 - Methods, Modules, and Packages
To Subscribe, use this Key
kansas-rugby-jig-spaghetti-seventeen-black
Status
Last Update
Fields
New Card
10/27/2024
Python’s {{c1::None}} is a special value indicating the absence of a value, distinct from False.
New Card
10/27/2024
To check if a value is None, Python uses the {{c1::is}} operator.
New Card
10/27/2024
{{c1::Positional arguments}} are passed in a specific order and correspond to function parameters by position.
New Card
10/27/2024
{{c1::Keyword arguments}} are passed by specifying the parameter name, allowing flexibility in argument order.
New Card
10/27/2024
Default parameter values can be set in a function using {{c1::parameter=value}} syntax.
New Card
10/27/2024
To gather arbitrary positional arguments in a tuple, use {{c1::*args}} in the function definition.
New Card
10/27/2024
Keyword arguments can be gathered into a dictionary by using {{c1::**kwargs}} in the function definition.
New Card
10/27/2024
A function’s documentation can be accessed by calling {{c1::help(function_name)}}.
New Card
10/27/2024
The {{c1::__doc__}} attribute stores a function’s docstring for inline documentation.
New Card
10/27/2024
Python functions are first-class citizens, meaning they can be {{c1::assigned to variables}} and passed as arguments.
New Card
10/27/2024
An {{c1::inner function}} is defined within another function, useful for encapsulating code.
New Card
10/27/2024
{{c1::Closures}} are inner functions that remember the environment in which they were created.
New Card
10/27/2024
A {{c1::lambda function}} in Python is a single-expression anonymous function, created with the lambda keyword.
New Card
10/27/2024
The yield statement in a {{c1::generator function}} creates an iterable generator object.
New Card
10/27/2024
Using {{c1::yield}} in a function allows it to produce values lazily, yielding items one at a time.
New Card
10/27/2024
{{c1::Generator comprehensions}} are similar to list comprehensions but use parentheses, e.g., (x for x in range(10)).
New Card
10/27/2024
A {{c1::decorator}} is a function that takes another function as input and extends its behavior without modifying it.
New Card
10/27/2024
In Python, {{c1::@decorator}} syntax applies a decorator to a function, modifying its behavior.
New Card
10/27/2024
The {{c1::global}} keyword lets a function modify a variable outside its local scope.
New Card
10/27/2024
The {{c1::locals()}} function returns a dictionary of the current local symbol table.
New Card
10/27/2024
The {{c1::globals()}} function returns a dictionary of the global symbol table.
New Card
10/27/2024
Variables prefixed with {{c1::__ (double underscores)}} in Python are intended for internal use.
New Card
10/27/2024
A function calling itself is known as {{c1::recursion}}.
New Card
10/27/2024
{{c1::try}} and {{c2::except}} are used in Python to handle exceptions safely.
New Card
10/27/2024
The keyword {{c1::finally}} in exception handling ensures code runs regardless of exceptions.
New Card
10/27/2024
A custom exception is created by defining a class that inherits from {{c1::Exception}}.
New Card
10/27/2024
Python modules are imported using the {{c1::import}} statement.
New Card
10/27/2024
To import a module with an alias, use {{c1::import module as alias}}.
New Card
10/27/2024
A package in Python is a directory with a special {{c1::__init__.py}} file, making it importable.
New Card
10/27/2024
The Python Standard Library provides {{c1::sys}} and {{c2::os}} for system-level operations.
New Card
10/27/2024
The {{c1::sys.path}} list in Python holds directories the interpreter searches for modules.
New Card
10/27/2024
Relative imports in Python use {{c1::.}} and {{c2::..}} for current and parent directories.
New Card
10/27/2024
The {{c1::from module import name}} syntax imports only specific elements from a module.
New Card
10/27/2024
Python’s {{c1::itertools}} library provides advanced iterator functions like {{c2::cycle()}} and {{c3::accumulate()}}.
New Card
10/27/2024
The {{c1::pprint}} library, or pretty print, is used to display data structures in a readable format.
New Card
10/27/2024
A deque from {{c1::collections}} is a double-ended queue useful for stack and queue operations.
New Card
10/27/2024
The {{c1::OrderedDict}} from collections maintains the order of insertion.
New Card
10/27/2024
The {{c1::enumerate()}} function allows iteration with automatic index assignment.
New Card
10/27/2024
The {{c1::zip()}} function combines multiple iterables element-wise into tuples.
New Card
10/27/2024
The {{c1::map()}} function applies a function to every item in an iterable.
New Card
10/27/2024
The {{c1::filter()}} function creates an iterable from items that match a condition.
New Card
10/27/2024
The {{c1::reduce()}} function, from functools, applies a function cumulatively to items in a sequence.
New Card
10/27/2024
The {{c1::any()}} function returns True if any element in an iterable is True.
New Card
10/27/2024
The {{c1::all()}} function returns True if all elements in an iterable are True.
New Card
10/27/2024
To sort an iterable, use the {{c1::sorted()}} function, which returns a new sorted list.
New Card
10/27/2024
The {{c1::sum()}} function returns the sum of items in an iterable.
New Card
10/27/2024
The {{c1::reversed()}} function returns an iterator in reverse order.
New Card
10/27/2024
The __main__ block in Python allows code to run only when the script is {{c1::executed directly}}.
New Card
10/27/2024
Docstrings should describe what a function or class does and can be accessed via {{c1::help()}}.
New Card
10/27/2024
Anonymous functions (lambda) are often used as arguments for {{c1::map, filter, and sorted}}.
New Card
10/27/2024
The Python standard library’s {{c1::math}} module includes functions like {{c2::sqrt}} and {{c3::factorial}}.
New Card
10/27/2024
The functools module includes {{c1::lru_cache}}, a decorator for caching function results.
New Card
10/27/2024
A decorator can modify a function without changing its source code, often used for {{c1::logging}}.
New Card
10/27/2024
Python’s collections module provides useful data structures such as {{c1::namedtuple}}.
New Card
10/27/2024
For structured data, Python offers the {{c1::dataclasses}} module to simplify class creation.
New Card
10/27/2024
Python’s os module provides access to environment variables via {{c1::os.environ}}.
New Card
10/27/2024
The keyword-only arguments are enforced in Python by placing a {{c1::*}} in the function signature.
Status
Last Update
Fields