Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Exploring Object Memory | How Python Manages Memory
Python Memory Management
Osio 1. Luku 5
single

single

Challenge: Exploring Object Memory

Pyyhkäise näyttääksesi valikon

Tehtävä

Pyyhkäise aloittaaksesi koodauksen

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]
  1. Import the sys module.
  2. Store the integer 100 in a variable called small_int and store the integer 1000 in a variable called large_int.
  3. Store the result of small_int is transactions[0] in a variable called is_cached — this checks whether the small integer cache is in effect.
  4. Store the result of large_int is 1000 in a variable called is_large_cached.
  5. Store the size of the transactions list in a variable called list_size, using sys.getsizeof().
  6. Store the reference count of small_int in a variable called ref_count, using sys.getrefcount().
  7. Print all four variables: is_cached, is_large_cached, list_size, and ref_count.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 5
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

some-alt