SlideShare a Scribd company logo
Investigating
Python Wats
Venmo
Hacker School
Recurse Center
!
@amygdalama
mathamy.com
WAT
Identity
Mutability
Scope
Identity
>>>	
  a	
  =	
  256	
  
>>>	
  b	
  =	
  256	
  
>>>	
  a	
  is	
  b	
  
???
>>>	
  a	
  =	
  256	
  
>>>	
  b	
  =	
  256	
  
>>>	
  a	
  is	
  b	
  
True
>>>	
  a	
  =	
  257	
  
>>>	
  b	
  =	
  257	
  
>>>	
  a	
  is	
  b	
  
???
>>>	
  a	
  =	
  257	
  
>>>	
  b	
  =	
  257	
  
>>>	
  a	
  is	
  b	
  
False
$	
  python	
  
!
!
-­‐5
…
255
256
-­‐5
…
255
256 a
>>>	
  a	
  =	
  256	
  
!
!
b
a
>>>	
  a	
  =	
  256	
  
>>>	
  b	
  =	
  256	
  
!
-­‐5
…
255
256
b
a
>>>	
  a	
  =	
  256	
  
>>>	
  b	
  =	
  256	
  
>>>	
  a	
  is	
  b	
  
True
-­‐5
…
255
256
a
…
255
256
…
257
>>>	
  a	
  =	
  257	
  
!
!
a
…
255
256
…
257
257 b
>>>	
  a	
  =	
  257	
  
>>>	
  b	
  =	
  257	
  
!
a
…
255
256
…
257
257 b
>>>	
  a	
  =	
  257	
  
>>>	
  b	
  =	
  257	
  
>>>	
  a	
  is	
  b	
  
False
>>>	
  a	
  =	
  257;	
  b	
  =	
  257	
  
>>>	
  a	
  is	
  b	
  
???
>>>	
  a	
  =	
  257;	
  b	
  =	
  257	
  
>>>	
  a	
  is	
  b	
  
True
>>>	
  a	
  =	
  257	
  
>>>	
  b	
  =	
  257	
  
>>>	
  a	
  is	
  b	
  
False	
  
!
>>>	
  a	
  =	
  257;	
  b	
  =	
  257	
  
>>>	
  a	
  is	
  b	
  
True
>>>	
  a	
  =	
  257	
  
>>>	
  
!
!
!
!
!
>>>	
  a	
  =	
  257	
  
>>>	
  source	
  =	
  "a	
  =	
  257"	
  
>>>	
  code_obj_a	
  =	
  compile(	
  
...	
  	
  	
  	
  	
  source=source,	
  
...	
  	
  	
  	
  	
  filename="",	
  
...	
  	
  	
  	
  	
  mode="exec")	
  
!
>>>	
  a	
  =	
  257	
  
>>>	
  source	
  =	
  "a	
  =	
  257"	
  
>>>	
  code_obj_a	
  =	
  compile(	
  
...	
  	
  	
  	
  	
  source=source,	
  
...	
  	
  	
  	
  	
  filename="",	
  
...	
  	
  	
  	
  	
  mode="exec")	
  
>>>	
  code_obj_a.co_consts	
  
(257,	
  None)
>>>	
  source	
  =	
  "b	
  =	
  257"	
  
>>>	
  code_obj_b	
  =	
  compile(	
  
...	
  	
  	
  	
  	
  source=source,	
  
...	
  	
  	
  	
  	
  filename="",	
  
...	
  	
  	
  	
  	
  mode="exec")	
  
!
>>>	
  source	
  =	
  "b	
  =	
  257"	
  
>>>	
  code_obj_b	
  =	
  compile(	
  
...	
  	
  	
  	
  	
  source=source,	
  
...	
  	
  	
  	
  	
  filename="",	
  
...	
  	
  	
  	
  	
  mode="exec")	
  
>>>	
  code_obj_b.co_consts	
  
(257,	
  None)
>>>	
  source	
  =	
  "a	
  =	
  257;	
  b	
  =	
  257"	
  
!
!
!
!
!
>>>	
  source	
  =	
  "a	
  =	
  257;	
  b	
  =	
  257"	
  
>>>	
  code_obj	
  =	
  compile(	
  	
  
...	
  	
  	
  	
  	
  source=source,	
  
...	
  	
  	
  	
  	
  filename="",	
  
...	
  	
  	
  	
  	
  mode="exec")	
  
!
>>>	
  source	
  =	
  "a	
  =	
  257;	
  b	
  =	
  257"	
  
>>>	
  code_obj	
  =	
  compile(	
  	
  
...	
  	
  	
  	
  	
  source=source,	
  
...	
  	
  	
  	
  	
  filename="",	
  
...	
  	
  	
  	
  	
  mode="exec")	
  
>>>	
  code_obj.co_consts	
  
(257,	
  None)
Mutability
>>>	
  row	
  =	
  [""]	
  *	
  3	
  
>>>	
  row	
  
['',	
  '',	
  '']	
  
!
!
!
!
>>>	
  row	
  =	
  [""]	
  *	
  3	
  
>>>	
  row	
  
['',	
  '',	
  '']	
  
>>>	
  board	
  =	
  [row]	
  *	
  3	
  
!
!
!
>>>	
  row	
  =	
  [""]	
  *	
  3	
  
>>>	
  row	
  
['',	
  '',	
  '']	
  
>>>	
  board	
  =	
  [row]	
  *	
  3	
  
>>>	
  board	
  
[['',	
  '',	
  ''],	
  
	
  ['',	
  '',	
  ''],	
  
	
  ['',	
  '',	
  '']]
>>>	
  board[0]	
  
['',	
  '',	
  '']	
  
!
>>>	
  board[0]	
  
['',	
  '',	
  '']	
  
>>>	
  board[0][0]	
  
''
>>>	
  board[0][0]	
  =	
  "X"	
  
!
!
!
>>>	
  board[0][0]	
  =	
  "X"	
  
>>>	
  board	
  
???	
  
!
>>>	
  board[0][0]	
  =	
  "X"	
  
>>>	
  board	
  
[['X',	
  '',	
  ''],	
  
	
  ['X',	
  '',	
  ''],	
  
	
  ['X',	
  '',	
  '']]
row
"" "" ""
>>>	
  row	
  =	
  [""]	
  *	
  3
>>>	
  board	
  =	
  [row]	
  *	
  3
row
board[0]
board[1]
board[2]
"" "" ""
>>>	
  board[0][0]	
  =	
  "X"
row
board[0]
board[1]
board[2]
"X" "" ""
Mutable Default
Arguments
def	
  append_cat(l=[]):	
  
!
!
!
!
!
!
def	
  append_cat(l=[]):	
  
	
  	
  	
  	
  l.append('cat')	
  
	
  	
  	
  	
  return	
  l	
  
!
!
!
!
def	
  append_cat(l=[]):	
  
	
  	
  	
  	
  l.append(‘cat’)	
  
	
  	
  	
  	
  return	
  l	
  
!
>>>	
  append_cat()	
  
???	
  
!
def	
  append_cat(l=[]):	
  
	
  	
  	
  	
  l.append(‘cat’)	
  
	
  	
  	
  	
  return	
  l	
  
!
>>>	
  append_cat()	
  
['cat']	
  
!
def	
  append_cat(l=[]):	
  
	
  	
  	
  	
  l.append(‘cat’)	
  
	
  	
  	
  	
  return	
  l	
  
!
>>>	
  append_cat()	
  
['cat']	
  
>>>	
  append_cat()	
  
???
def	
  append_cat(l=[]):	
  
	
  	
  	
  	
  l.append(‘cat’)	
  
	
  	
  	
  	
  return	
  l	
  
!
>>>	
  append_cat()	
  
['cat']	
  
>>>	
  append_cat()	
  
['cat',	
  'cat']
def	
  append_cat(l=[]):	
  
	
  	
  	
  	
  l.append(‘cat’)	
  
	
  	
  	
  	
  return	
  l	
  
!
>>>	
  append_cat.__defaults__	
  
???	
  
!
def	
  append_cat(l=[]):	
  
	
  	
  	
  	
  l.append(‘cat’)	
  
	
  	
  	
  	
  return	
  l	
  
!
>>>	
  append_cat.__defaults__	
  
([],)	
  
!
def	
  append_cat(l=[]):	
  
	
  	
  	
  	
  l.append('cat')	
  
	
  	
  	
  	
  return	
  l	
  
!
>>>	
  append_cat()	
  
>>>	
  append_cat.__defaults__	
  
???	
  
def	
  append_cat(l=[]):	
  
	
  	
  	
  	
  l.append('cat')	
  
	
  	
  	
  	
  return	
  l	
  
!
>>>	
  append_cat()	
  
>>>	
  append_cat.__defaults__	
  
(['cat'],)	
  
>>>	
  append_cat.__defaults__	
  
(['cat'],)	
  
!
!
>>>	
  append_cat.__defaults__	
  
(['cat'],)	
  
>>>	
  _[0].append('dragon')	
  
!
>>>	
  append_cat.__defaults__	
  
(['cat'],)	
  
>>>	
  _[0].append('dragon')	
  
>>>	
  append_cat()	
  
???
>>>	
  append_cat.__defaults__	
  
(['cat'],)	
  
>>>	
  _[0].append('dragon')	
  
>>>	
  append_cat()	
  
['cat',	
  'dragon',	
  'cat']
Scope
>>>	
  a	
  =	
  1	
  
!
!
!
!
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  return	
  a	
  
!
!
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  return	
  a	
  
!
>>>	
  foo()	
  
???
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  return	
  a	
  
!
>>>	
  foo()	
  
1
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  return	
  a	
  
>>>	
  foo()	
  
???
• locals()	
  	
  	
  	
  	
  #	
  {}	
  
!
!
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  return	
  a	
  
>>>	
  foo()	
  
???
• locals()	
  	
  	
  	
  	
  #	
  {}	
  
!
!
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  return	
  a	
  
>>>	
  foo()	
  
???
• locals()	
  	
  	
  	
  	
  #	
  {}	
  
• enclosing	
  	
  	
  	
  #	
  {}	
  
!
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  return	
  a	
  
>>>	
  foo()	
  
???
• locals()	
  	
  	
  	
  	
  #	
  {}	
  
• enclosing	
  	
  	
  	
  #	
  {}	
  
!
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  return	
  a	
  
>>>	
  foo()	
  
???
• locals()	
  	
  	
  	
  	
  #	
  {}	
  
• enclosing	
  	
  	
  	
  #	
  {}	
  
• globals()	
  	
  	
  	
  #	
  {'a':	
  1}	
  
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  return	
  a	
  
>>>	
  foo()	
  
???
• locals()	
  	
  	
  	
  	
  #	
  {}	
  
• enclosing	
  	
  	
  	
  #	
  {}	
  
✓ globals()	
  	
  	
  	
  #	
  {'a':	
  1}	
  
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  return	
  a	
  
>>>	
  foo()	
  
1
• locals()	
  	
  	
  	
  	
  #	
  {}	
  
• enclosing	
  	
  	
  	
  #	
  {}	
  
✓ globals()	
  	
  	
  	
  #	
  {'a':	
  1}	
  
• builtins	
  	
  	
  	
  	
  #	
  {'True':	
  True,…}
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  return	
  a	
  
>>>	
  foo()	
  
1
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  return	
  a	
  
!
>>>	
  from	
  dis	
  import	
  dis	
  
!
!
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  return	
  a	
  
!
>>>	
  from	
  dis	
  import	
  dis	
  
>>>	
  dis(foo)	
  
	
  	
  2	
  	
  	
  	
  	
  	
  	
  0	
  LOAD_GLOBAL	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  (a)	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  3	
  RETURN_VALUE	
  	
  	
  
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  a	
  +=	
  1	
  
...	
  	
  	
  	
  	
  return	
  a	
  
!
>>>	
  foo()	
  
???
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  a	
  +=	
  1	
  
...	
  	
  	
  	
  	
  return	
  a	
  
!
>>>	
  foo()	
  
UnboundLocalError:	
  local	
  
variable	
  'a'	
  referenced	
  
before	
  assignment
“When you make an
assignment to a variable in a
scope, that variable becomes
local to that scope.”
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  #	
  a	
  +=	
  1	
  
...	
  	
  	
  	
  	
  a	
  =	
  a	
  +	
  1	
  
...	
  	
  	
  	
  	
  return	
  a
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  #	
  a	
  +=	
  1	
  
...	
  	
  	
  	
  	
  a	
  =	
  a	
  +	
  1	
  
...	
  	
  	
  	
  	
  return	
  a
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  #	
  a	
  +=	
  1	
  
...	
  	
  	
  	
  	
  a	
  =	
  a	
  +	
  1	
  
...	
  	
  	
  	
  	
  return	
  a
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  a	
  +=	
  1	
  
...	
  	
  	
  	
  	
  return	
  a	
  
...	
  	
  
>>>	
  dis(foo)	
  
	
  	
  2	
  	
  	
  	
  	
  	
  	
  0	
  LOAD_FAST	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  (a)	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  3	
  LOAD_CONST	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  (1)	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  6	
  INPLACE_ADD	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  7	
  STORE_FAST	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  (a)	
  	
  
!
	
  	
  3	
  	
  	
  	
  	
  	
  10	
  LOAD_FAST	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  (a)	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  13	
  RETURN_VALUE	
  	
  	
  	
  	
  	
  
>>>	
  a	
  =	
  1	
  
>>>	
  def	
  foo():	
  
...	
  	
  	
  	
  	
  a	
  +=	
  1	
  
...	
  	
  	
  	
  	
  return	
  a	
  
...	
  	
  
>>>	
  dis(foo)	
  
	
  	
  2	
  	
  	
  	
  	
  	
  	
  0	
  LOAD_FAST	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  (a)	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  3	
  LOAD_CONST	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  (1)	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  6	
  INPLACE_ADD	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  7	
  STORE_FAST	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  (a)	
  	
  
!
	
  	
  3	
  	
  	
  	
  	
  	
  10	
  LOAD_FAST	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  0	
  (a)	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  13	
  RETURN_VALUE	
  	
  	
  	
  	
  	
  
“Knowledge is power —
it’s measured in wats.”	

!
- Rose Ames
Thank you!
@amygdalama
mathamy.com
Links
• https://www.destroyallsoftware.com/talks/wat	

• http://akaptur.github.io/blog/2013/10/29/a-python-puzzle/	

• https://docs.python.org/3.4/c-api/long.html	

• https://docs.python.org/3/reference/
compound_stmts.html#function-definitions	

• http://effbot.org/zone/default-values.htm	

• https://docs.python.org/3/reference/
executionmodel.html#naming-and-binding	

• http://eli.thegreenplace.net/2011/05/15/understanding-
unboundlocalerror-in-python/	

• http://rose.github.io/posts/measured-in-wats/

More Related Content

KEY
Refactor like a boss
PDF
The Magic Of Elixir
PDF
Slaying the Dragon: Implementing a Programming Language in Ruby
PDF
Python WATs: Uncovering Odd Behavior
PPTX
P3 2018 python_regexes
PDF
[131]해커의 관점에서 바라보기
PDF
Introduction to Groovy
PDF
Barely Legal Xxx Perl Presentation
Refactor like a boss
The Magic Of Elixir
Slaying the Dragon: Implementing a Programming Language in Ruby
Python WATs: Uncovering Odd Behavior
P3 2018 python_regexes
[131]해커의 관점에서 바라보기
Introduction to Groovy
Barely Legal Xxx Perl Presentation

What's hot (20)

PDF
Hidden Gems of Ruby 1.9
PDF
Intro to OTP in Elixir
KEY
Programming Haskell Chapter8
PPTX
Down the rabbit hole, profiling in Django
PDF
PubNative Tracker
ZIP
Ruby on Rails: Tasty Burgers
PDF
The Ring programming language version 1.6 book - Part 48 of 189
KEY
Use cases in the code with AOP
PDF
Tame cloud complexity with F#-powered DSLs
PDF
穏やかにファイルを削除する
PDF
Combinator parsing
PPTX
PDF
Serhii Korolenko - Passing Security By
KEY
Elegant APIs
PDF
Perl6 grammars
PDF
The Ring programming language version 1.6 book - Part 185 of 189
PDF
Unbreakable: The Craft of Code
ODP
The bones of a nice Python script
PPTX
The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...
PDF
... now write an interpreter (PHPem 2016)
Hidden Gems of Ruby 1.9
Intro to OTP in Elixir
Programming Haskell Chapter8
Down the rabbit hole, profiling in Django
PubNative Tracker
Ruby on Rails: Tasty Burgers
The Ring programming language version 1.6 book - Part 48 of 189
Use cases in the code with AOP
Tame cloud complexity with F#-powered DSLs
穏やかにファイルを削除する
Combinator parsing
Serhii Korolenko - Passing Security By
Elegant APIs
Perl6 grammars
The Ring programming language version 1.6 book - Part 185 of 189
Unbreakable: The Craft of Code
The bones of a nice Python script
The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...
... now write an interpreter (PHPem 2016)
Ad

Similar to Investigating Python Wats (20)

ODP
PDF
Slides chapter3part1 ruby-forjavaprogrammers
PDF
λ | Lenses
PPTX
GE8151 Problem Solving and Python Programming
PDF
Ruby - Uma Introdução
PDF
JVMLS 2016. Coroutines in Kotlin
PDF
A Taste of Python - Devdays Toronto 2009
PPTX
Python Workshop
PDF
Python Functions (PyAtl Beginners Night)
PDF
ScotRuby - Dark side of ruby
PDF
Introduction to Python
PDF
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
PDF
replacing `import` with `accio`
PDF
Ruby closures, how are they possible?
PDF
Parse Everything With Elixir
PDF
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
PDF
RedDot Ruby Conf 2014 - Dark side of ruby
PDF
Perl 6 in Context
PDF
PDF
Elixir -Tolerância a Falhas para Adultos - GDG Campinas
Slides chapter3part1 ruby-forjavaprogrammers
λ | Lenses
GE8151 Problem Solving and Python Programming
Ruby - Uma Introdução
JVMLS 2016. Coroutines in Kotlin
A Taste of Python - Devdays Toronto 2009
Python Workshop
Python Functions (PyAtl Beginners Night)
ScotRuby - Dark side of ruby
Introduction to Python
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
replacing `import` with `accio`
Ruby closures, how are they possible?
Parse Everything With Elixir
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
RedDot Ruby Conf 2014 - Dark side of ruby
Perl 6 in Context
Elixir -Tolerância a Falhas para Adultos - GDG Campinas
Ad

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
Teaching material agriculture food technology
PDF
KodekX | Application Modernization Development
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Cloud computing and distributed systems.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine learning based COVID-19 study performance prediction
NewMind AI Weekly Chronicles - August'25 Week I
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Unlocking AI with Model Context Protocol (MCP)
Per capita expenditure prediction using model stacking based on satellite ima...
Advanced methodologies resolving dimensionality complications for autism neur...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
MIND Revenue Release Quarter 2 2025 Press Release
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Dropbox Q2 2025 Financial Results & Investor Presentation
Teaching material agriculture food technology
KodekX | Application Modernization Development
Digital-Transformation-Roadmap-for-Companies.pptx
Cloud computing and distributed systems.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Review of recent advances in non-invasive hemoglobin estimation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf

Investigating Python Wats

  • 3. WAT
  • 6. >>>  a  =  256   >>>  b  =  256   >>>  a  is  b   ???
  • 7. >>>  a  =  256   >>>  b  =  256   >>>  a  is  b   True
  • 8. >>>  a  =  257   >>>  b  =  257   >>>  a  is  b   ???
  • 9. >>>  a  =  257   >>>  b  =  257   >>>  a  is  b   False
  • 11. -­‐5 … 255 256 a >>>  a  =  256   ! !
  • 12. b a >>>  a  =  256   >>>  b  =  256   ! -­‐5 … 255 256
  • 13. b a >>>  a  =  256   >>>  b  =  256   >>>  a  is  b   True -­‐5 … 255 256
  • 15. a … 255 256 … 257 257 b >>>  a  =  257   >>>  b  =  257   !
  • 16. a … 255 256 … 257 257 b >>>  a  =  257   >>>  b  =  257   >>>  a  is  b   False
  • 17. >>>  a  =  257;  b  =  257   >>>  a  is  b   ???
  • 18. >>>  a  =  257;  b  =  257   >>>  a  is  b   True
  • 19. >>>  a  =  257   >>>  b  =  257   >>>  a  is  b   False   ! >>>  a  =  257;  b  =  257   >>>  a  is  b   True
  • 20. >>>  a  =  257   >>>   ! ! ! ! !
  • 21. >>>  a  =  257   >>>  source  =  "a  =  257"   >>>  code_obj_a  =  compile(   ...          source=source,   ...          filename="",   ...          mode="exec")   !
  • 22. >>>  a  =  257   >>>  source  =  "a  =  257"   >>>  code_obj_a  =  compile(   ...          source=source,   ...          filename="",   ...          mode="exec")   >>>  code_obj_a.co_consts   (257,  None)
  • 23. >>>  source  =  "b  =  257"   >>>  code_obj_b  =  compile(   ...          source=source,   ...          filename="",   ...          mode="exec")   !
  • 24. >>>  source  =  "b  =  257"   >>>  code_obj_b  =  compile(   ...          source=source,   ...          filename="",   ...          mode="exec")   >>>  code_obj_b.co_consts   (257,  None)
  • 25. >>>  source  =  "a  =  257;  b  =  257"   ! ! ! ! !
  • 26. >>>  source  =  "a  =  257;  b  =  257"   >>>  code_obj  =  compile(     ...          source=source,   ...          filename="",   ...          mode="exec")   !
  • 27. >>>  source  =  "a  =  257;  b  =  257"   >>>  code_obj  =  compile(     ...          source=source,   ...          filename="",   ...          mode="exec")   >>>  code_obj.co_consts   (257,  None)
  • 29. >>>  row  =  [""]  *  3   >>>  row   ['',  '',  '']   ! ! ! !
  • 30. >>>  row  =  [""]  *  3   >>>  row   ['',  '',  '']   >>>  board  =  [row]  *  3   ! ! !
  • 31. >>>  row  =  [""]  *  3   >>>  row   ['',  '',  '']   >>>  board  =  [row]  *  3   >>>  board   [['',  '',  ''],    ['',  '',  ''],    ['',  '',  '']]
  • 32. >>>  board[0]   ['',  '',  '']   !
  • 33. >>>  board[0]   ['',  '',  '']   >>>  board[0][0]   ''
  • 34. >>>  board[0][0]  =  "X"   ! ! !
  • 35. >>>  board[0][0]  =  "X"   >>>  board   ???   !
  • 36. >>>  board[0][0]  =  "X"   >>>  board   [['X',  '',  ''],    ['X',  '',  ''],    ['X',  '',  '']]
  • 37. row "" "" "" >>>  row  =  [""]  *  3
  • 38. >>>  board  =  [row]  *  3 row board[0] board[1] board[2] "" "" ""
  • 39. >>>  board[0][0]  =  "X" row board[0] board[1] board[2] "X" "" ""
  • 42. def  append_cat(l=[]):          l.append('cat')          return  l   ! ! ! !
  • 43. def  append_cat(l=[]):          l.append(‘cat’)          return  l   ! >>>  append_cat()   ???   !
  • 44. def  append_cat(l=[]):          l.append(‘cat’)          return  l   ! >>>  append_cat()   ['cat']   !
  • 45. def  append_cat(l=[]):          l.append(‘cat’)          return  l   ! >>>  append_cat()   ['cat']   >>>  append_cat()   ???
  • 46. def  append_cat(l=[]):          l.append(‘cat’)          return  l   ! >>>  append_cat()   ['cat']   >>>  append_cat()   ['cat',  'cat']
  • 47. def  append_cat(l=[]):          l.append(‘cat’)          return  l   ! >>>  append_cat.__defaults__   ???   !
  • 48. def  append_cat(l=[]):          l.append(‘cat’)          return  l   ! >>>  append_cat.__defaults__   ([],)   !
  • 49. def  append_cat(l=[]):          l.append('cat')          return  l   ! >>>  append_cat()   >>>  append_cat.__defaults__   ???  
  • 50. def  append_cat(l=[]):          l.append('cat')          return  l   ! >>>  append_cat()   >>>  append_cat.__defaults__   (['cat'],)  
  • 52. >>>  append_cat.__defaults__   (['cat'],)   >>>  _[0].append('dragon')   !
  • 53. >>>  append_cat.__defaults__   (['cat'],)   >>>  _[0].append('dragon')   >>>  append_cat()   ???
  • 54. >>>  append_cat.__defaults__   (['cat'],)   >>>  _[0].append('dragon')   >>>  append_cat()   ['cat',  'dragon',  'cat']
  • 55. Scope
  • 56. >>>  a  =  1   ! ! ! !
  • 57. >>>  a  =  1   >>>  def  foo():   ...          return  a   ! !
  • 58. >>>  a  =  1   >>>  def  foo():   ...          return  a   ! >>>  foo()   ???
  • 59. >>>  a  =  1   >>>  def  foo():   ...          return  a   ! >>>  foo()   1
  • 60. >>>  a  =  1   >>>  def  foo():   ...          return  a   >>>  foo()   ???
  • 61. • locals()          #  {}   ! ! >>>  a  =  1   >>>  def  foo():   ...          return  a   >>>  foo()   ???
  • 62. • locals()          #  {}   ! ! >>>  a  =  1   >>>  def  foo():   ...          return  a   >>>  foo()   ???
  • 63. • locals()          #  {}   • enclosing        #  {}   ! >>>  a  =  1   >>>  def  foo():   ...          return  a   >>>  foo()   ???
  • 64. • locals()          #  {}   • enclosing        #  {}   ! >>>  a  =  1   >>>  def  foo():   ...          return  a   >>>  foo()   ???
  • 65. • locals()          #  {}   • enclosing        #  {}   • globals()        #  {'a':  1}   >>>  a  =  1   >>>  def  foo():   ...          return  a   >>>  foo()   ???
  • 66. • locals()          #  {}   • enclosing        #  {}   ✓ globals()        #  {'a':  1}   >>>  a  =  1   >>>  def  foo():   ...          return  a   >>>  foo()   1
  • 67. • locals()          #  {}   • enclosing        #  {}   ✓ globals()        #  {'a':  1}   • builtins          #  {'True':  True,…} >>>  a  =  1   >>>  def  foo():   ...          return  a   >>>  foo()   1
  • 68. >>>  a  =  1   >>>  def  foo():   ...          return  a   ! >>>  from  dis  import  dis   ! !
  • 69. >>>  a  =  1   >>>  def  foo():   ...          return  a   ! >>>  from  dis  import  dis   >>>  dis(foo)      2              0  LOAD_GLOBAL                    0  (a)                        3  RETURN_VALUE      
  • 70. >>>  a  =  1   >>>  def  foo():   ...          a  +=  1   ...          return  a   ! >>>  foo()   ???
  • 71. >>>  a  =  1   >>>  def  foo():   ...          a  +=  1   ...          return  a   ! >>>  foo()   UnboundLocalError:  local   variable  'a'  referenced   before  assignment
  • 72. “When you make an assignment to a variable in a scope, that variable becomes local to that scope.”
  • 73. >>>  a  =  1   >>>  def  foo():   ...          #  a  +=  1   ...          a  =  a  +  1   ...          return  a
  • 74. >>>  a  =  1   >>>  def  foo():   ...          #  a  +=  1   ...          a  =  a  +  1   ...          return  a
  • 75. >>>  a  =  1   >>>  def  foo():   ...          #  a  +=  1   ...          a  =  a  +  1   ...          return  a
  • 76. >>>  a  =  1   >>>  def  foo():   ...          a  +=  1   ...          return  a   ...     >>>  dis(foo)      2              0  LOAD_FAST                        0  (a)                        3  LOAD_CONST                      1  (1)                        6  INPLACE_ADD                                          7  STORE_FAST                      0  (a)     !    3            10  LOAD_FAST                        0  (a)                      13  RETURN_VALUE            
  • 77. >>>  a  =  1   >>>  def  foo():   ...          a  +=  1   ...          return  a   ...     >>>  dis(foo)      2              0  LOAD_FAST                        0  (a)                        3  LOAD_CONST                      1  (1)                        6  INPLACE_ADD                                          7  STORE_FAST                      0  (a)     !    3            10  LOAD_FAST                        0  (a)                      13  RETURN_VALUE            
  • 78. “Knowledge is power — it’s measured in wats.” ! - Rose Ames
  • 80. Links • https://www.destroyallsoftware.com/talks/wat • http://akaptur.github.io/blog/2013/10/29/a-python-puzzle/ • https://docs.python.org/3.4/c-api/long.html • https://docs.python.org/3/reference/ compound_stmts.html#function-definitions • http://effbot.org/zone/default-values.htm • https://docs.python.org/3/reference/ executionmodel.html#naming-and-binding • http://eli.thegreenplace.net/2011/05/15/understanding- unboundlocalerror-in-python/ • http://rose.github.io/posts/measured-in-wats/