Weekly backup.
This commit is contained in:
33
20220516160421-evaluation_tardive.org
Normal file
33
20220516160421-evaluation_tardive.org
Normal file
@@ -0,0 +1,33 @@
|
||||
:PROPERTIES:
|
||||
:ID: 831fbfd2-c668-4099-b2d7-ecae734b9ec4
|
||||
:mtime: 20220519083124
|
||||
:ctime: 20220516160421
|
||||
:END:
|
||||
#+title: Evaluation tardive
|
||||
|
||||
* Introduction
|
||||
#+BEGIN_SRC python :results output
|
||||
class A:
|
||||
def function(self):
|
||||
return A()
|
||||
|
||||
a = A()
|
||||
A = int
|
||||
print(f"{a.function() = }")
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS:
|
||||
: a.function() = 0
|
||||
|
||||
* Explications
|
||||
* Le code contenu dans une fonction n'est exécuté uniquement lorsque celle-ci est invoquée. Ainsi, la référence à la
|
||||
fonction non déclarée ~A~ par la méthode ~A.function~ ne génère pas d'erreur,
|
||||
* Durant l'exécution de la méthode ~A.function~,
|
||||
|
||||
However, during the execution Python will bind the name A from
|
||||
the outer scope, which means that function method will return a newly created int instance.
|
||||
|
||||
|
||||
* Références
|
||||
* [[https://medium.com/@saint_sdmn/10-hardest-python-questions-98986c8cd309][10 Hardest Python Questions - Medium]]
|
||||
|
Reference in New Issue
Block a user