python notes (@pythonnotes) header
python notes (@pythonnotes) profile picture

python tips for myself

Toronto, Ontario
Joined November 2022
Photo by python notes (@pythonnotes)Photo by python notes (@pythonnotes)Photo by python notes (@pythonnotes)Photo by python notes (@pythonnotes)Photo by python notes (@pythonnotes)Photo by python notes (@pythonnotes)Photo by python notes (@pythonnotes)Photo by python notes (@pythonnotes)Photo by python notes (@pythonnotes)Photo by python notes (@pythonnotes)
f-string is becoming a dominant way to format strings in Python thanks to its powerful and concise syntax. But do you know backslashes may not appear inside the curly braces {}. Here is an sample and explanation.
1
121
In CPython, due to the GIL, only one thread can execute Python code at once. #Python
1
96
A key difference between three class builders of #Python “data class” is that collections.namedtuple and typing.NamedTuple build tuple subclasses, therefore the instances are immutable. By default, @ dataclass produces mutable classes.
1
126
Python uses data buffer to temporarily store data before it is sent to output device.
1
96
Concurrency provides a way to structure a solution to solve a problem that can be (not necessarily) be parallelizable. Parallelism is just a special case of concurrency. #Python
1
74
The walrus operator was introduced in PEP 572. peps.python.org/pep-0572/
62
The class collections.deque is a thread-safe double-ended queue designed for fast inserting and removing from both ends.
70
You can make a list act as a stack or a queue (if you use .append and .pop(0), you get FIFO behavior). But inserting and removing from the head of a list (the 0-index end) is costly because the entire list must be shifted in memory.
1
62
Most NumPy and SciPy functions are implemented in C or C++, and can leverage all CPU cores because they release Python’s GIL (Global Interpreter Lock).
46
Replying to @pythonnotes
For advanced array and matrix operations, NumPy is the choice, which is the reason why Python became mainstream in scientific computing applications. NumPy implements multidimensional, homogeneous arrays and matrix types that hold not only numbers but also user-defined records.
51
SciPy is a library, written on top of NumPy, offering many scientific computing algorithms from linear algebra, numerical calculus, and statistics. SciPy is fast and reliable because it leverages the widely used C and Fortran codebase from the Netlib Repository .
2
1
2
74
For advanced array and matrix operations, NumPy is the choice, which is the reason why Python became mainstream in scientific computing applications. NumPy implements multidimensional, homogeneous arrays and matrix types that hold not only numbers but also user-defined records.
1
85
Arrays support all mutable sequence operations (including .pop, .insert, and .extend), as well as additional methods for fast loading and saving, such as .frombytes and .tofile.
39
Everything in #Python is an object, including functions and class definitions and basic values like integers, floats, Booleans, and strings.
49
This post is a good explanation to static methods in Python: julien.danjou.info/guide-pyt…
When a #Python function is defined, the Python bytecode compiler determines how to fetch a variable that appears in it based on some variable lookup logic.
To specify keyword-only arguments when defining a function, name them after the argument prefixed with *. If you don’t want to support variable positional arguments but still want keyword-only arguments, put a * by itself in the signature. #Python #pythonprogramming
In #Python, first-class functions can be helpful for programming in a functional style, of which one hallmark is using higher-order functions, such as `map`, `filter`, `reduce`. But, in same cases, list comprehensions or generator expressions can be better choices.
Liskov Substitution Principle (LSP) is defined 'subtype-of' in terms of supported operations, which is called behavioral subtyping.
2
Duck typing is popular in Python, JavaScript, and Ruby, only enforced at runtime, and more flexible than nominal typing that adopted by C++, Java, and C#.