Start using f-string to align code and make strings readable, clean, and explicit

Image for post
Image for post
Photo by Taylor Vick on Unsplash

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? …


My interpretation of the Zen of Python and more tips to make code nice and tidy

Image for post
Image for post
Photo by Scott Webb on Unsplash.

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.

The Zen of Python?

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…


Python tips tutorial

Guide : A fast start using data sharing while discard complex detail.

Image for post
Image for post
https://unsplash.com/photos/CyFBmFEsytU

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.

Where to start?

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


Quick Start Tutorial

Guide: The fastest way to download images from Unsplash.

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.

Concept in brief

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


Python tips tutorial

Guide: Use concurrent module to propel your work.

Image for post
Image for post
https://unsplash.com/photos/SYTO3xs06fU

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.

What Are Multithreading and Multiprocessing?

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

About

Hannibal Liang

Dreaming of making programming more concise and decent.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store