Herramientas de usuario

Herramientas del sitio


wiki2:python:code_notes

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
wiki2:python:code_notes [2018/12/12 07:22]
alfred [Tricks]
wiki2:python:code_notes [2020/06/20 10:02] (actual)
Línea 1: Línea 1:
-====== Python ​code notes ======+====== Python ​snippets ​======
 ===== Getters & setters ===== ===== Getters & setters =====
 <code python> <code python>
Línea 47: Línea 47:
 </​code>​ </​code>​
  
-===== Conditional tricks =====+===== Conditional tricks ​(Short circuit) ​=====
 You can use the conditional operators ''​and''​ and ''​or''​ for deciding how to execute code. Next piece won't print ''​hola''​. You can use the conditional operators ''​and''​ and ''​or''​ for deciding how to execute code. Next piece won't print ''​hola''​.
 <​code>​ <​code>​
Línea 54: Línea 54:
     ​     ​
 False and foo() False and foo()
 +</​code>​
 +
 +===== See the low level actions =====
 +
 +We can see the low level actions of a function with the ''​dis''​ package:
 +
 +<code python>
 +>>>​ def func(a):
 +...     a += 10
 +...     ​return a
 +... 
 +>>>​ import dis
 +>>>​ dis.dis(func)
 +  2           0 LOAD_FAST ​               0 (a)
 +              3 LOAD_CONST ​              1 (10)
 +              6 INPLACE_ADD ​        
 +              7 STORE_FAST ​              0 (a)
 +
 +  3          10 LOAD_FAST ​               0 (a)
 +             13 RETURN_VALUE ​
 </​code>​ </​code>​
wiki2/python/code_notes.1544599322.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)