Avoid Duplication in Your Code

Avoid Duplication in Your Code

While writing code, we should avoid duplication because:

  • It is redundant
  • If we make a change to one piece of code, we need to remember to make the same change to another piece of code. Otherwise, we will introduce bugs into our code.

In the code above, we use the filter X['date'] > date(2021, 2, 8) twice. To avoid duplication, we can assign the repeated code to a variable or a function.

My previous tips on good Python practices.

Search

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran