String formatting means embedding expressions inside string literals. In most of the Python tutorials for beginners, the first task starts with the “Hello World” project, which makes
string the most familiar variable type.
However, once you start adding parameters inside a longer string, your code would be less concise and readable. For example:
Obviously, the string concatenation looks bad and wordy, so the Python Software Foundation invented a function called
.format() to shorten the syntax:
It’s more intuitive but still not easily readable, so why not adopt new ways? …
According to Clean Code: A Handbook of Agile Software Craftsmanship, “The ratio of time spent reading vs. writing is well over 10:1.”
Typically, aesthetic programming was not a critical issue when we were studying in school. Individuals then follow their style when writing in Python. However, the work may be quite undesirable whenever we have to spend most of the time understanding one’s implicit code, which could also happen to others when reading our code. Therefore, let’s focus on the Zen of Python and some improvement tips to solve the problem.
For those who haven’t seen it before, type and execute
import this in your Python interpreter, and 19 guiding principles penned by Tim Peters will show…
As a novice in multithreading and multiprocessing, the motivation for working in parallelism is to propel your code execution. However, get stuck as soon as you make the tasks more complex.
This article focuses on “Quick Start”, not the full explanation, but I promise that this would make you easier to understand before diving into real solid knowledge.
The most common challenge is the data sharing among multithreading and multiprocessing, and lots of resources related to this topic have already existed. Take a look and see how people explain the identical subject in defferent ways. …
Traditionally, we download files by clicking each of them, but what if we need more and more files? We may expect programming could help us out. In this article, extend the idea from the last topic about “multithreading” and use the practical instance to bring you more intuition on when to use it. It would be easier to start with “image” since it’s the most common file we face every day.
Let’s take downloading images from Unsplash as our today’s task, which the idea can be extended to all kinds of files download, and look into the detail in the next paragraph. …
Sometimes, we spend lots of time waiting for the results to output when coding, but there’s a way to accelerate it. In this section, we are aiming to build multithreading in Python and share some ideas in five minutes.
To know a new terminology, it is good to search on Google first, but in short, these are techniques for creating multiple tasks working at the same time in your background.
First of all, what are threads? If you are using Mac, open Activity Monitor and click on the CPU button at the top of the window. …