Soumettre la recherche
Mettre en ligne
Python WATs: Uncovering Odd Behavior
•
2 j'aime
•
2,217 vues
Amy Hanlon
Suivre
Presented at PyGotham 2014.
Lire moins
Lire la suite
Ingénierie
Signaler
Partager
Signaler
Partager
1 sur 90
Télécharger maintenant
Télécharger pour lire hors ligne
Recommandé
Investigating Python Wats
Investigating Python Wats
Amy Hanlon
ScotRuby - Dark side of ruby
ScotRuby - Dark side of ruby
Gautam Rege
RedDot Ruby Conf 2014 - Dark side of ruby
RedDot Ruby Conf 2014 - Dark side of ruby
Gautam Rege
MySQLConf2009: Taking ActiveRecord to the Next Level
MySQLConf2009: Taking ActiveRecord to the Next Level
Blythe Dunham
Class 6: Lists & dictionaries
Class 6: Lists & dictionaries
Marc Gouw
Introduction to Groovy
Introduction to Groovy
Anton Arhipov
Python for High School Programmers
Python for High School Programmers
Siva Arunachalam
Introduction to Search Systems - ScaleConf Colombia 2017
Introduction to Search Systems - ScaleConf Colombia 2017
Toria Gibbs
Recommandé
Investigating Python Wats
Investigating Python Wats
Amy Hanlon
ScotRuby - Dark side of ruby
ScotRuby - Dark side of ruby
Gautam Rege
RedDot Ruby Conf 2014 - Dark side of ruby
RedDot Ruby Conf 2014 - Dark side of ruby
Gautam Rege
MySQLConf2009: Taking ActiveRecord to the Next Level
MySQLConf2009: Taking ActiveRecord to the Next Level
Blythe Dunham
Class 6: Lists & dictionaries
Class 6: Lists & dictionaries
Marc Gouw
Introduction to Groovy
Introduction to Groovy
Anton Arhipov
Python for High School Programmers
Python for High School Programmers
Siva Arunachalam
Introduction to Search Systems - ScaleConf Colombia 2017
Introduction to Search Systems - ScaleConf Colombia 2017
Toria Gibbs
Use cases in the code with AOP
Use cases in the code with AOP
Andrzej Krzywda
A Search Index is Not a Database Index - Full Stack Toronto 2017
A Search Index is Not a Database Index - Full Stack Toronto 2017
Toria Gibbs
Exhibition of Atrocity
Exhibition of Atrocity
Michael Pirnat
7li7w devcon5
7li7w devcon5
Kerry Buckley
Search Engines: How They Work and Why You Need Them
Search Engines: How They Work and Why You Need Them
Toria Gibbs
Getting to know Arel
Getting to know Arel
Ray Zane
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
Yury Chemerkin
MongoDB.local Austin 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local Austin 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
David Golden
Tips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB
1 the ruby way
1 the ruby way
Luis Doubrava
Perl.Hacks.On.Vim
Perl.Hacks.On.Vim
Lin Yo-An
Most common mistakes of workshops applicants
Most common mistakes of workshops applicants
Dominik Wojciechowski
MongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query Pitfalls
MongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query Pitfalls
MongoDB
MongoDB.local Sydney 2019: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local Sydney 2019: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB
Python 1
Python 1
Ramin Najjarbashi
Elixir
Elixir
Andrew Babichev
2 BytesC++ course_2014_c2_ flow of control
2 BytesC++ course_2014_c2_ flow of control
kinan keshkeh
Next Level Testing
Next Level Testing
James Saryerwinnie
Swift Study #2
Swift Study #2
chanju Jeon
Refactor like a boss
Refactor like a boss
gsterndale
What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)
Kerry Buckley
Contenu connexe
Tendances
Use cases in the code with AOP
Use cases in the code with AOP
Andrzej Krzywda
A Search Index is Not a Database Index - Full Stack Toronto 2017
A Search Index is Not a Database Index - Full Stack Toronto 2017
Toria Gibbs
Exhibition of Atrocity
Exhibition of Atrocity
Michael Pirnat
7li7w devcon5
7li7w devcon5
Kerry Buckley
Search Engines: How They Work and Why You Need Them
Search Engines: How They Work and Why You Need Them
Toria Gibbs
Getting to know Arel
Getting to know Arel
Ray Zane
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
Yury Chemerkin
MongoDB.local Austin 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local Austin 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
David Golden
Tips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB
1 the ruby way
1 the ruby way
Luis Doubrava
Perl.Hacks.On.Vim
Perl.Hacks.On.Vim
Lin Yo-An
Most common mistakes of workshops applicants
Most common mistakes of workshops applicants
Dominik Wojciechowski
MongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query Pitfalls
MongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query Pitfalls
MongoDB
MongoDB.local Sydney 2019: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local Sydney 2019: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB
Python 1
Python 1
Ramin Najjarbashi
Elixir
Elixir
Andrew Babichev
2 BytesC++ course_2014_c2_ flow of control
2 BytesC++ course_2014_c2_ flow of control
kinan keshkeh
Next Level Testing
Next Level Testing
James Saryerwinnie
Swift Study #2
Swift Study #2
chanju Jeon
Tendances
(20)
Use cases in the code with AOP
Use cases in the code with AOP
A Search Index is Not a Database Index - Full Stack Toronto 2017
A Search Index is Not a Database Index - Full Stack Toronto 2017
Exhibition of Atrocity
Exhibition of Atrocity
7li7w devcon5
7li7w devcon5
Search Engines: How They Work and Why You Need Them
Search Engines: How They Work and Why You Need Them
Getting to know Arel
Getting to know Arel
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
Gareth hayes. non alphanumeric javascript-php and shared fuzzing
MongoDB.local Austin 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local Austin 2018: Tips and Tricks for Avoiding Common Query Pitfalls
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
Tips and Tricks for Avoiding Common Query Pitfalls
Tips and Tricks for Avoiding Common Query Pitfalls
1 the ruby way
1 the ruby way
Perl.Hacks.On.Vim
Perl.Hacks.On.Vim
Most common mistakes of workshops applicants
Most common mistakes of workshops applicants
MongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query Pitfalls
MongoDB.local Seattle 2019: Tips & Tricks for Avoiding Common Query Pitfalls
MongoDB.local Sydney 2019: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local Sydney 2019: Tips and Tricks for Avoiding Common Query Pitfalls
Python 1
Python 1
Elixir
Elixir
2 BytesC++ course_2014_c2_ flow of control
2 BytesC++ course_2014_c2_ flow of control
Next Level Testing
Next Level Testing
Swift Study #2
Swift Study #2
Similaire à Python WATs: Uncovering Odd Behavior
Refactor like a boss
Refactor like a boss
gsterndale
What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)
Kerry Buckley
CoffeeScript
CoffeeScript
Scott Leberknight
Introduction to Python
Introduction to Python
UC San Diego
Seven Languages in Seven Days: Ruby
Seven Languages in Seven Days: Ruby
Zach Leatherman
Perl 6 in Context
Perl 6 in Context
lichtkind
Adventures in Optimization
Adventures in Optimization
David Golden
A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009
Jordan Baker
Beautiful python - PyLadies
Beautiful python - PyLadies
Alicia Pérez
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
Qiangning Hong
Php Code Audits (PHP UK 2010)
Php Code Audits (PHP UK 2010)
Damien Seguy
Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVM
Dierk König
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
Rick Copeland
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
Michael Pirnat
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammers
Giovanni924
Python Puzzlers
Python Puzzlers
Tendayi Mawushe
Iterators, Hashes, and Arrays
Iterators, Hashes, and Arrays
Blazing Cloud
Writing Apps the Google-y Way (Brisbane)
Writing Apps the Google-y Way (Brisbane)
Pamela Fox
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
Plotly
Functional programming in ruby
Functional programming in ruby
Koen Handekyn
Similaire à Python WATs: Uncovering Odd Behavior
(20)
Refactor like a boss
Refactor like a boss
What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)
CoffeeScript
CoffeeScript
Introduction to Python
Introduction to Python
Seven Languages in Seven Days: Ruby
Seven Languages in Seven Days: Ruby
Perl 6 in Context
Perl 6 in Context
Adventures in Optimization
Adventures in Optimization
A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009
Beautiful python - PyLadies
Beautiful python - PyLadies
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
Php Code Audits (PHP UK 2010)
Php Code Audits (PHP UK 2010)
Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVM
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
Slides chapter3part1 ruby-forjavaprogrammers
Slides chapter3part1 ruby-forjavaprogrammers
Python Puzzlers
Python Puzzlers
Iterators, Hashes, and Arrays
Iterators, Hashes, and Arrays
Writing Apps the Google-y Way (Brisbane)
Writing Apps the Google-y Way (Brisbane)
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
Functional programming in ruby
Functional programming in ruby
Dernier
multiple access in wireless communication
multiple access in wireless communication
panditadesh123
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
Romil Mishra
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.ppt
Narmatha D
DM Pillar Training Manual.ppt will be useful in deploying TPM in project
DM Pillar Training Manual.ppt will be useful in deploying TPM in project
ssuserb6619e
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
Dr SOUNDIRARAJ N
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
Mark Billinghurst
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
BootNeck1
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
VICTOR MAESTRE RAMIREZ
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
Mebane Rash
"Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ...
Erbil Polytechnic University
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
sdickerson1
Crushers to screens in aggregate production
Crushers to screens in aggregate production
ChinnuNinan
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
saravananr517913
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
aditya806802
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
Tagore Institute of Engineering And Technology
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptx
VelmuruganTECE
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
121011101441
Configuration of IoT devices - Systems managament
Configuration of IoT devices - Systems managament
BharaniDharan195623
Crystal Structure analysis and detailed information pptx
Crystal Structure analysis and detailed information pptx
achiever3003
Virtual memory management in Operating System
Virtual memory management in Operating System
Rashmi Bhat
Dernier
(20)
multiple access in wireless communication
multiple access in wireless communication
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.ppt
DM Pillar Training Manual.ppt will be useful in deploying TPM in project
DM Pillar Training Manual.ppt will be useful in deploying TPM in project
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
"Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ...
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
Crushers to screens in aggregate production
Crushers to screens in aggregate production
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptx
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
Configuration of IoT devices - Systems managament
Configuration of IoT devices - Systems managament
Crystal Structure analysis and detailed information pptx
Crystal Structure analysis and detailed information pptx
Virtual memory management in Operating System
Virtual memory management in Operating System
Python WATs: Uncovering Odd Behavior
1.
Python WATs: Uncovering Odd Behavior
2.
Hacker School Alum Software
Engineer at Venmo ! @amygdalama mathamy.com Who am I?
3.
Allison Kaptur Tom Ballinger Gary
Bernhardt Thanks!
4.
Identity Mutability Scope Themes
5.
a. Trivia b. Why? c.
Tips for theme in themes:
6.
Identity
7.
> "" is
"" ??? Trivia
8.
> "" is
"" True Trivia
9.
> 0 is
0 ??? Trivia
10.
> 0 is
0 True Trivia
11.
> [] is
[] ??? Trivia
12.
> [] is
[] False Trivia
13.
> {} is
{} ??? Trivia
14.
> {} is
{} False Trivia
15.
> a =
256 > b = 256 > a is b ??? Trivia
16.
> a =
256 > b = 256 > a is b True Trivia
17.
> a =
257 > b = 257 > a is b ??? Trivia
18.
> a =
257 > b = 257 > a is b False Trivia
19.
> a =
257; b = 257 > a is b ??? Trivia
20.
> a =
257; b = 257 > a is b True Trivia
21.
a Why?-‐5 … 255 256 … > a =
256 ! !
22.
a Why?-‐5 … 255 256 … b > a =
256 > b = 256 !
23.
a Why?-‐5 … 255 256 … b > a =
256 > b = 256 > a is b True
24.
a Why?… 255 256 … 257 > a =
257 ! !
25.
a Why?… 255 256 … 257 257 b > a
= 257 > b = 257 !
26.
a Why?… 255 256 … 257 257 b > a
= 257 > b = 257 > a is b False
27.
> a =
257 > b = 257 > id(a) == id(b) False Why?
28.
> a =
257; b = 257 > id(a) == id(b) True Why?
29.
• Use ==
instead of is to compare values • Exceptions: • x is None • tests for identity Tips
30.
Mutability
31.
> faves =
["cats", "dragons"] ! ! ! Trivia
32.
> faves =
["cats", "dragons"] > temp = faves ! ! Trivia
33.
> faves =
["cats", "dragons"] > temp = faves > temp.append("rainbows") ! Trivia
34.
> faves =
["cats", "dragons"] > temp = faves > temp.append("rainbows") > temp ??? Trivia
35.
> faves =
["cats", "dragons"] > temp = faves > temp.append("rainbows") > temp ["cats", "dragons", "rainbows"] Trivia
36.
> faves =
["cats", "dragons"] > temp = faves > temp.append("rainbows") > faves ??? Trivia
37.
> faves =
["cats", "dragons"] > temp = faves > temp.append("rainbows") > faves ["cats", "dragons", "rainbows"] Trivia
38.
faves Why? "cats" "dragons" > faves =
["cats", "dragons"]
39.
faves Why? "cats" "dragons" > temp =
faves temp
40.
faves Why? "cats" "dragons" "rainbows" > temp.append("rainbows") temp
41.
• lists [] •
dictionaries {} • sets () Tip: Mutable Objects
42.
> temp =
faves[:] > temp = list(faves) Tip: Make Real Copies
43.
> temp =
[] > for element in faves: temp.append(element) Tip: Shallow Copy
44.
> faves =
[["cats", "dragons"]] ! ! ! Tip: Deep Copy
45.
> faves =
[["cats", "dragons"]] > temp = faves[:] ! ! Tip: Deep Copy
46.
> faves =
[["cats", "dragons"]] > temp = faves[:] > temp[0].append("rainbows") ! Tip: Deep Copy
47.
> faves =
[["cats", "dragons"]] > temp = faves[:] > temp[0].append("rainbows") > faves ??? Tip: Deep Copy
48.
> faves =
[["cats", "dragons"]] > temp = faves[:] > temp[0].append("rainbows") > faves [["cats", "dragons", "rainbows"]] Tip: Deep Copy
49.
• For arbitrarily-nested lists,
make deep copies ! > import copy > temp = copy.deepcopy(faves) Tip: Deep Copy
50.
Mutable Default Arguments
51.
def append_cat(l=[]): ! Trivia
52.
def append_cat(l=[]):
l.append(‘cat’) return l Trivia
53.
def append_cat(l=[]):
l.append(‘cat’) return l ! > append_cat() ??? ! Trivia
54.
def append_cat(l=[]):
l.append(‘cat’) return l ! > append_cat() [‘cat’] ! Trivia
55.
def append_cat(l=[]):
l.append(‘cat’) return l ! > append_cat() [‘cat’] > append_cat() ??? Trivia
56.
def append_cat(l=[]):
l.append(‘cat’) return l ! > append_cat() [‘cat’] > append_cat() [‘cat’, ‘cat’] Trivia
57.
def append_cat(l=[]):
l.append(‘cat’) return l ! > append_cat.func_defaults ??? Why?
58.
def append_cat(l=[]):
l.append(‘cat’) return l ! > append_cat.func_defaults ([],) Why?
59.
def append_cat(l=[]):
l.append('cat') return l ! > append_cat() > append_cat.func_defaults ??? Why?
60.
def append_cat(l=[]):
l.append('cat') return l ! > append_cat() > append_cat.func_defaults (['cat'],) Why?
61.
> append_cat.func_defaults (['cat'],)
! ! Why?
62.
> append_cat.func_defaults (['cat'],)
> _[0].append('dragon') ! Why?
63.
> append_cat.func_defaults (['cat'],)
> _[0].append('dragon') > append_cat() ??? Why?
64.
> append_cat.func_defaults (['cat'],)
> _[0].append('dragon') > append_cat() ['cat', 'dragon', 'cat'] Why?
65.
def append_cat(l=None): ! ! ! Tip:
Use None
66.
def append_cat(l=None):
if l is None: l = [] ! Tip: Use None
67.
def append_cat(l=None):
if l is None: l = [] l.append(‘cat') return l Tip: Use None
68.
def sorting_hat(student, cache={}):
! ! ! ! ! ! Tip: Take Advantage!
69.
def sorting_hat(student, cache={}):
if student in cache: print "Used cache!" return cache[student] else: ! ! Tip: Take Advantage!
70.
def sorting_hat(student, cache={}):
if student in cache: print "Used cache!" return cache[student] else: house = slow_alg(student) cache[student] = house return house Tip: Take Advantage!
71.
> sorting_hat('Amy Hanlon')
'Ravenclaw' ! ! ! ! Tip: Take Advantage!
72.
> sorting_hat('Amy Hanlon')
'Ravenclaw' > sorting_hat('Amy Hanlon') Used cache! ‘Ravenclaw' ! Tip: Take Advantage!
73.
> sorting_hat('Amy Hanlon')
'Ravenclaw' > sorting_hat('Amy Hanlon') Used cache! ‘Ravenclaw' > sorting_hat.func_defaults ({'Amy Hanlon': 'Ravenclaw'},) Tip: Take Advantage!
74.
Scope
75.
> a =
1 ! ! ! ! Trivia
76.
> a =
1 > def foo(): return a ! ! Trivia
77.
> a =
1 > def foo(): return a ! > foo() ??? Trivia
78.
> a =
1 > def foo(): return a ! > foo() 1 Trivia
79.
Namespaces! ! • locals() ! Why?
80.
Namespaces! ! • locals() •
globals() # {'a' : 1} Why?
81.
Namespaces! ! • locals() •
globals() # {'a' : 1} • __builtins__ Why?
82.
> a =
1 > def foo(): return a ! > foo() 1 Trivia
83.
> a =
1 > def foo(): a += 1 return a ! > foo() ??? Trivia
84.
> a =
1 > def foo(): a += 1 return a ! > foo() UnboundLocalError: local variable 'a' referenced before assignment Trivia
85.
“When you make
an assignment to a variable in a scope, that variable becomes local to that scope.” Why?
86.
Why? > a =
1 > def foo(): # a += 1 a = a + 1 return a
87.
> a =
1 > def foo(): global a a += 1 return a > foo() 2 > a 2 Tip: Use global
88.
> def foo(a):
a += 1 return a > a = 1 > a = foo(a) 2 Tip: Don’t Use global
89.
Links • https://docs.python.org/3/ • http://eli.thegreenplace.net/ •
http://akaptur.github.io/blog/ 2013/10/29/a-python-puzzle/ • http://mathamy.com/python-wats- mutable-default-arguments.html
90.
Thank you! Questions?
Télécharger maintenant