Understanding Core Concepts of Python

Understanding Core Concepts of Python

Introduction In Python development, understanding the reference differences between mutable objects (such as lists and dictionaries) and immutable objects (such as integers and strings) is crucial. This not only affects code performance but can also lead to subtle bugs. As an experienced developer, I will share insights from practical development to help you master this … Read more

The ‘Shared List’ Trap in Python Class Attributes: Why Your Friend Became Everyone’s Friend?

The 'Shared List' Trap in Python Class Attributes: Why Your Friend Became Everyone's Friend?

Today, I want to share a very common pitfall in Python—strange behavior when the default value of a class attribute is a mutable object (like a list). A seemingly simple example Let’s first look at a simple <span>Person</span> class definition: class Person: def __init__(self, name:str, frients:list=[]): self.name = name self.frients = frients def show_frients(self): print(f"{self.name}, … Read more