> Programming

Python knowledge

1. Mutable & Immutable In python, built-in types are classified as mutable and immutable. immutable: tuple, string, number, bool mutable: list, dict, set example city_list = ['New York', 'London', 'Tokyo'] city_list.append('Paris') print(city_list) # ['New York', 'London', 'Tokyo', 'Paris'] tuple_a = (1, 2) tuple_a[0] = 3 # error, since tuple_a is immutable, we can't modify it tuple_b = ([], 0) tuple_b[0].append(1) # success, because the address of the first element didn't change print(tuple_b) # ([1], 0) Conlusion Mutable objects are often used in the situations where we want to do updates.

Continue reading

Author's picture

LI WEI

苟日新,日日新,又日新

Not yet

Tokyo