How to use it and when to use it.

Getter and setter are used in many object-oriented programming languages, (click the link for knowing how it works in Java), however, python provides a much easier way to use getter and setter with its built-in @property decorator.

Wait, decorator? Sounds familiar, right? If you haven’t heard of it before, or if you have heard of it but you are not sure what it does, maybe check this out: What is a Decorator in Python? Sweeter your Python code in an advanced way with the help of decorators.

Let’s start with a normal class that we usually create and use.


Sweeter your Python code in an advanced way with the help of decorators.

When you view lots of source code on GitHub or on other platforms, you might see an @ above the function. But many of us don’t know what it does. I didn’t either until I learned this interesting feature of Python — Decorator.

By the example code below, you should know that in Python, even a function is an object, and can be assigned as an argument for another function.

Then let’s try to wrap a function into another function.

We call f1 function and f2 function is f1’s argument — it will go through the wrapper() and return…

Local, Enclose, Global and Build-in

Each programming language has its own variable scope. For python, we could simply follow the LEGB rule that includes

Local, Enclose, Global, and Built-in.

In this article, we will use a few examples to understand their feature and how to access objects of different scopes.

Local; Enclose; Global Variable

We start from this example first

There are three variables with the same name called x, which represent different scopes.

x = 'global var'def outer():
# y is local variable for outer(), enclose variable for inner()
x = 'enclose var'
def inner():
x = 'local var'
print('inner: {}'.format(x))
print('outer: {}'.format(x))

master json.loads() & json.dumps()

JSON is a key-value pairs data format available for many languages, including Python, Ruby, PHP, Java, etc. It is easy to read and write as well as create and manipulate. NoSQL databases use this data type to store data too.
(Want to know what’s the difference between SQL and NoSQL databases? Check this: SQL vs No SQL Database Comparison)

Today we will go through the four basic but most important functions of the JSON module in Python.

  • json.loads()
  • json.dumps()
  • json.load()
  • json.dump()

First of all, let us know how JSON is decoded in Python. You can also use this table to…

Part II Coding In Practically

After understanding the difference between multithreading and multiprocessing, if you are no sure about what are these two concepts, check this previous article: Multithreading vs. Multiprocessing in Python
Part I Talking In Theory
, and now we are going to realize it by python code!


Implementation and interpretation

During the whole examples, we will focus on a function called go_sleep() .

Generally, when we run a function multiple times, it executes the first one first, then executes the second one after completion, and so on.

In this case, we run go_sleep() five times and record the start and finish time to see how much…

Part I Talking In Theory

Before we start discussing multithreading and multiprocessing, let me briefly introduce what is process and thread in computer and program:

  • A process is what we call a program that has been loaded into memory along with all the resources it needs to operate.
  • A thread is the unit of execution within a process.
  • A process can have multiple threads running as a part of it, each thread uses the process’s memory space and shares the same memory space with other threads while the processes have separate memory.

After knowing the relationship between processes and threads, now we could forward to…

SQL stands for Structured Query Language. ‘SQL database’ is a relational database, while the ‘NoSQL database’ is non-relational, they are both aim to store data but how they actually work? Today will introduce the difference between these two kind of databases.

Straight to the point, here are the key difference between them:

Cloud platform comparison and pick the one that meets your needs

The website project that I took during my master’s degree made me spend tons of hard work and research on website development from scratch.

But before development, the first problem I encountered was that I needed the most suitable cloud platform as the server for hosting the website, but which one should I choose?

I tided up all the notes for comparing these three cloud platforms:
Amazon AWS, Microsoft AZURE and Google GCP, and will share the reasons why choose AWS and my personal experience using the AWS platform.


Amazon Web Services

As the leader in the public could market…

A generator in python is used to create iterable objects.

You might not hear about yield, but you must know about return and use it frequently during development. In fact, yield is similar to return and if you know how to use return, you will know how to use yield in a very short time!

The difference between these two is that while return terminates a function entirely, yield pauses the function and saving all its states, continues the function by successive calls.

Let’s see how it works by code

Create a function that will always add 10 from the original number then return the result as…

Object-Oriented Programming in Python

Everything in python is object. Classes, functions and even simple data types, such as integer and float.

Object-Oriented Programming makes the program easy to understand as well as efficient. Use it wisely could let development faster and easier! OOP has several advantages, such as reusable, maintainable, easy to expansion, flexibility and secure, etc. For more detail about the benefits, please refer to this article from EDUCBA: Advantage of OOP.

This article will introduce the three main concepts in Object-Oriented Programming and how they work:

Inheritance, Encapsulation and Polymorphism

We will create an Employee class as an example. In this case, the Employee class has…

Allie Hsu

a tech enthusiast who is keen to develop new skills

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