pythonnotes's profile picture. python tips for myself

python notes

@pythonnotes

python tips for myself

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.

pythonnotes's tweet image. 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.

In CPython, due to the GIL, only one thread can execute Python code at once. #Python


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.

pythonnotes's tweet image. 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.

Python uses data buffer to temporarily store data before it is sent to output device.

pythonnotes's tweet image. Python uses data buffer to temporarily store data before it is sent to output device.

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


Everything in #Python is an object, including functions and class definitions and basic values like integers, floats, Booleans, and strings.


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.

pythonnotes's tweet image. 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

pythonnotes's tweet image. 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.

pythonnotes's tweet image. 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.


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#.


Loading...

Something went wrong.


Something went wrong.