Seksjon 1. Kapittel 5
single
Challenge: Exploring Object Memory
Sveip for å vise menyen
Oppgave
Sveip for å begynne å kode
You are analyzing the memory behavior of a small data processing script. Your goal is to inspect reference counts, observe the integer cache, and measure object sizes using the tools covered in this section.
You are given the following list of transaction amounts:
transactions = [100, 200, 100, 300, 100, 200]
- Import the
sysmodule. - Store the integer
100in a variable calledsmall_intand store the integer1000in a variable calledlarge_int. - Store the result of
small_int is transactions[0]in a variable calledis_cached— this checks whether the small integer cache is in effect. - Store the result of
large_int is 1000in a variable calledis_large_cached. - Store the size of the
transactionslist in a variable calledlist_size, usingsys.getsizeof(). - Store the reference count of
small_intin a variable calledref_count, usingsys.getrefcount(). - Print all four variables:
is_cached,is_large_cached,list_size, andref_count.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 5
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår