0

What's the reference and reference count in python?

9th Jan 2020, 7:11 AM
Yusof
Yusof - avatar
2 Respostas
+ 1
Python deletes data objects automatically after they fall out of use. For that reason Python keeps track of how many 'names' that object has. a = [1, 2, 3] # list created, ref count 1 b = a # ref count 2 c = {'list': a} # ref count 3 del a # one name deleted, rc 2 del c['list'] # ref count 1 b = 42 # name b given to something else; original list's ref count now 0. Python is free to delete the object.
9th Jan 2020, 8:27 AM
HonFu
HonFu - avatar