Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
¿Qué sucede en la memoria al descomprimir una colección?

Decir

 list1=[4,8,12] a,b,c=list1

la salida es a=4,b=8,c=12 .

mi confusión

El instructor nos dijo que no es como si a se asignara a 4 , b a 8 y c a 12 . No entendí claramente lo que dijo (aunque lo escuché repetidamente varias veces). Estaba diciendo algo como que el objeto se crea para 4 y a se asigna a 4 . Pero, ¿cuál es la diferencia entre esto y lo que he presentado a continuación en la figura?

diagrama escrito a mano

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Lo que es engañoso de su imagen es que implica que a , b y c hacen referencia a segmentos de list1 . Sin embargo, si cambia list1 , encontrará que a , b y c no se ven afectados por ese cambio.

Una mejor manera de dibujar la imagen podría ser mostrar 4, 8 y 12 separados de list1 :

 list1-->[ ][ ][ ] | | | VVV 4 8 12 ^ ^ ^ | | | abc

Todas las variables son independientes entre sí, aunque algunas de ellas (por ejemplo list1[0] y a ) actualmente apuntan a los mismos valores.

Para decirlo de otra manera: decir a = list1[0] es decir "evaluar list1[0] y asignar a para hacer referencia a ese valor en este momento ", que no es lo mismo que decir "hacer que a sea un alias para list1[0] ".

over 4 years ago · Santiago Trujillo Report

0

Prueba esto:

 # define the list list1=[4,8,12] # reserve 3 memory spaces and unpack the values from list into them # those memory spaces will contain one integer each one of the size of # sys.getsizeof(int()) == 28 bytes (Python 3) # a,b and c are actually pointers to those memory spaces a,b,c=list1 print(a,b,c) # change the first value of the list list1[0] = 56 print(list1) # now check that indeed "a" is not the same pointer than "list1[0]" print(a)

Pero

Debes tener cuidado con este tipo de asignaciones con listas, prueba también esto:

 list2 = list1 print(list1, list2) # then change any of them list1 [0] = -1 # check that "list2" is pointing to the same memory address than "list1" print(list1, list2)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!