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.
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…
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.
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'
x = 'local var'
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.
First of all, let us know how JSON is decoded in Python. You can also use this table to…
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!
During the whole examples, we will focus on a function called
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…
Before we start discussing multithreading and multiprocessing, let me briefly introduce what is process and thread in computer and program:
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:
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.
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.
Create a function that will always add 10 from the original number then return the result as…
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:
We will create an Employee class as an example. In this case, the Employee class has…