SlideShare a Scribd company logo
Python 
Aliasing 
Copyright © Software Carpentry 2010 
This work is licensed under the Creative Commons Attribution License 
See http://software-carpentry.org/license.html for more information.
An alias is a second name for a piece of data 
Python Aliasing
An alias is a second name for a piece of data 
Often easier (and more useful) than making a 
sseeccoonndd ccooppyy 
Python Aliasing
An alias is a second name for a piece of data 
Often easier (and more useful) than making a 
sseeccoonndd ccooppyy 
If the data is immutable, aliases don't matter 
Python Aliasing
An alias is a second name for a piece of data 
Often easier (and more useful) than making a 
sseeccoonndd ccooppyy 
If the data is immutable, aliases don't matter 
Because the data can't change 
Python Aliasing
An alias is a second name for a piece of data 
Often easier (and more useful) than making a 
sseeccoonndd ccooppyy 
If the data is immutable, aliases don't matter 
Because the data can't change 
But if data can change, aliases can result in a lot 
of hard-to-find bugs 
Python Aliasing
Aliasing happens whenever one variable's value 
is assigned to another variable 
Python Aliasing
Aliasing happens whenever one variable's value 
is assigned to another variable 
first = 'isaac' 
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
first 'isaac' 
Python Aliasing
Aliasing happens whenever one variable's value 
is assigned to another variable 
first = 'isaac' 
second = first 
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
first 
second 
'isaac' 
Python Aliasing
Aliasing happens whenever one variable's value 
is assigned to another variable 
first = 'isaac' 
second = first 
But as we've already seen… 
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
first 
second 
'isaac' 
Python Aliasing
Aliasing happens whenever one variable's value 
is assigned to another variable 
first = 'isaac' 
second = first 
But as we've already seen… 
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
first = first + ' newton' 
first 
second 
'isaac' 
'isaac newton' 
Python Aliasing
But lists are mutable 
Python Aliasing
But lists are mutable 
first = ['isaac'] 
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
first 
'isaac' 
Python Aliasing
But lists are mutable 
first = ['isaac'] 
second = first 
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
first 
second 
'isaac' 
Python Aliasing
But lists are mutable 
first = ['isaac'] 
second = first 
first = first.append('newton') 
pppprrrriiiinnnntttt first 
['isaac', 'newton'] 
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
first 
second 
'isaac' 'newton' 
Python Aliasing
But lists are mutable 
first = ['isaac'] 
second = first 
first = first.append('newton') 
pppprrrriiiinnnntttt first 
['isaac', 'newton'] 
pppprrrriiiinnnntttt second 
['isaac', 'newton'] 
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
first 
second 
'isaac' 'newton' 
Python Aliasing
But lists are mutable 
first = ['isaac'] 
second = first 
first = first.append('newton') 
pppprrrriiiinnnntttt first 
['isaac', 'newton'] 
pppprrrriiiinnnntttt second 
['isaac', 'newton'] 
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
first 
Didn't explicitly 
second 
'isaac' 'newton' 
modify second 
Python Aliasing
But lists are mutable 
first = ['isaac'] 
second = first 
first = first.append('newton') 
pppprrrriiiinnnntttt first 
['isaac', 'newton'] 
pppprrrriiiinnnntttt second 
['isaac', 'newton'] 
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
first 
Didn't explicitly 
second 
'isaac' 'newton' 
modify second 
A side effect 
Python Aliasing
Example: use lists of lists 
to implement a 2D grid 
Python Aliasing
3 
5 
Example: use lists of lists 
to implement a 2D grid 
7 
2 
6 
5 
7 5 8 
5 6 3 
3 2 4 
4 
3 
8 
Python Aliasing
3 
5 
Example: use lists of lists 
to implement a 2D grid 
7 
2 
6 
5 
7 5 8 
5 6 3 
3 2 4 
grid 
4 
3 
8 
Python Aliasing
3 
5 
Example: use lists of lists 
to implement a 2D grid 
7 
2 
6 
5 
7 5 8 
5 6 3 
3 2 4 
grid[0] 
4 
3 
8 
Python Aliasing
3 
5 
Example: use lists of lists 
to implement a 2D grid 
7 
2 
6 
5 
7 5 8 
5 6 3 
3 2 4 
grid[0][1] 
4 
3 
8 
Python Aliasing
# Correct code 
grid = [] 
ffffoooorrrr x iiiinnnn range(N): 
temp = [] 
ffffoooorrrr y iiiinnnn range(N): 
temp.append(1) 
grid.append(temp) 
Python Aliasing
# Correct code 
grid = [] 
ffffoooorrrr x iiiinnnn range(N): 
temp = [] 
Outer "spine" of structure 
ffffoooorrrr y iiiinnnn range(N): 
temp.append(1) 
grid.append(temp) 
Python Aliasing
# Correct code 
grid = [] 
ffffoooorrrr x iiiinnnn range(N): 
temp = [] 
ffffoooorrrr y iiiinnnn range(N): 
temp.append(1) 
grid.append(temp) 
Add N sub-lists to outer list 
Python Aliasing
# Correct code 
grid = [] 
ffffoooorrrr x iiiinnnn range(N): 
temp = [] 
ffffoooorrrr y iiiinnnn range(N): 
temp.append(1) 
grid.append(temp) 
Create a sublist of N 1's 
Python Aliasing
# Equivalent code 
grid = [] 
ffffoooorrrr x iiiinnnn range(N): 
grid.append([]) 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
Python Aliasing
# Equivalent code 
grid = [] 
ffffoooorrrr x iiiinnnn range(N): 
grid.append([]) 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
Last element of outer list is the sublist currently 
being filled in 
Python Aliasing
# Incorrect code 
grid = [] 
EMPTY = [] 
ffffoooorrrr x iiiinnnn range(N): 
grid.append(EMPTY) 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
Python Aliasing
# Incorrect code 
grid = [] 
EMPTY = [] 
ffffoooorrrr x iiiinnnn range(N): 
# Equivalent code 
grid = [] 
ffffoooorrrr x iiiinnnn range(N): 
grid.append(EMPTY) 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
grid.append([]) 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
Python Aliasing
# Incorrect code 
grid = [] 
EMPTY = [] 
ffffoooorrrr x iiiinnnn range(N): 
Aren't meaningful variable 
names supposed to be 
grid.append(EMPTY) 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
a good thing? 
Python Aliasing
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
grid = [] 
EMPTY = [] 
ffffoooorrrr x iiiinnnn range(N): 
x 0 
grid.append(EMPTY) 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
grid 
EMPTY 
Python Aliasing
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
grid = [] 
EMPTY = [] 
ffffoooorrrr x iiiinnnn range(N): 
x 0 
grid.append(EMPTY) 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
grid 
EMPTY 
Python Aliasing
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
grid = [] 
EMPTY = [] 
ffffoooorrrr x iiiinnnn range(N): 
x 
y 
0 
0 
grid.append(EMPTY) 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
grid 
EMPTY 
Python Aliasing
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
grid = [] 
EMPTY = [] 
ffffoooorrrr x iiiinnnn range(N): 
x 
y 
0 
0 
grid.append(EMPTY) 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
grid 
EMPTY 
1 
Python Aliasing
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
grid = [] 
EMPTY = [] 
ffffoooorrrr x iiiinnnn range(N): 
x 
y 
0 
2 
grid.append(EMPTY) 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
grid 
EMPTY 
1 1 1 
Python Aliasing
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
grid = [] 
EMPTY = [] 
ffffoooorrrr x iiiinnnn range(N): 
x 
y 
1 
2 
grid.append(EMPTY) 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
grid 
EMPTY 
1 1 1 
Python Aliasing
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
grid = [] 
EMPTY = [] 
ffffoooorrrr x iiiinnnn range(N): 
x 
y 
1 
2 
grid.append(EMPTY) 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
grid 
EMPTY 
1 1 1 
You see the problem... 
Python Aliasing
No Aliasing 
ffiirrsstt == [[]] 
second = [] 
Python Aliasing
No Aliasing Aliasing 
ffiirrsstt == [[]] ffiirrsstt == [[]] 
second = [] second = first 
Python Aliasing
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
grid = [] 
ffffoooorrrr x iiiinnnn range(N): 
grid.append([]) 
x 0 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
grid 
Python Aliasing
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
grid = [] 
ffffoooorrrr x iiiinnnn range(N): 
grid.append([]) 
x 0 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
grid 
Python Aliasing
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
grid = [] 
ffffoooorrrr x iiiinnnn range(N): 
grid.append([]) 
x 
y 
0 
2 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
grid 
1 1 1 
Python Aliasing
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
grid = [] 
ffffoooorrrr x iiiinnnn range(N): 
grid.append([]) 
x 
y 
1 
2 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
grid 
1 1 1 
Python Aliasing
vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee 
grid = [] 
ffffoooorrrr x iiiinnnn range(N): 
grid.append([]) 
x 
y 
1 
0 
ffffoooorrrr y iiiinnnn range(N): 
grid[-1].append(1) 
grid 
1 1 1 
1 
Python Aliasing
If aliasing can cause bugs, why allow it? 
Python Aliasing
If aliasing can cause bugs, why allow it? 
1. Some languages don't 
Python Aliasing
If aliasing can cause bugs, why allow it? 
1. Some languages don't 
Or at lleeaasstt aappppeeaarr nnoott ttoo 
Python Aliasing
If aliasing can cause bugs, why allow it? 
1. Some languages don't 
Or at lleeaasstt aappppeeaarr nnoott ttoo 
2. Aliasing a million-element list is more efficient 
than copying it 
Python Aliasing
If aliasing can cause bugs, why allow it? 
1. Some languages don't 
Or at lleeaasstt aappppeeaarr nnoott ttoo 
2. Aliasing a million-element list is more efficient 
than copying it 
3. Sometimes really do want to update a structure 
in place 
Python Aliasing
created by 
Greg Wilson 
October 2010 
Copyright © Software Carpentry 2010 
This work is licensed under the Creative Commons Attribution License 
See http://software-carpentry.org/license.html for more information.

More Related Content

What's hot

Introduction to Python and TensorFlow
Introduction to Python and TensorFlowIntroduction to Python and TensorFlow
Introduction to Python and TensorFlow
Bayu Aldi Yansyah
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin I
Guixing Bai
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance Python
Ian Ozsvald
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
Marwan Osman
 
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
PyNSK
 
Python легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачиPython легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачи
Maxim Kulsha
 
Matlab and Python: Basic Operations
Matlab and Python: Basic OperationsMatlab and Python: Basic Operations
Matlab and Python: Basic Operations
Wai Nwe Tun
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
Matt Harrison
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced python
Charles-Axel Dein
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101Ankur Gupta
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimizationg3_nittala
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
Qiangning Hong
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
Wei-Yuan Chang
 
Advanced Python, Part 2
Advanced Python, Part 2Advanced Python, Part 2
Advanced Python, Part 2
Zaar Hai
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015
Phillip Trelford
 
Kotlin collections
Kotlin collectionsKotlin collections
Kotlin collections
Myeongin Woo
 
Learn python in 20 minutes
Learn python in 20 minutesLearn python in 20 minutes
Learn python in 20 minutes
Sidharth Nadhan
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
Eueung Mulyana
 
Argparse: Python command line parser
Argparse: Python command line parserArgparse: Python command line parser
Argparse: Python command line parser
Timo Stollenwerk
 

What's hot (20)

Introduction to Python and TensorFlow
Introduction to Python and TensorFlowIntroduction to Python and TensorFlow
Introduction to Python and TensorFlow
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin I
 
Lists
ListsLists
Lists
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance Python
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5
 
Python легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачиPython легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачи
 
Matlab and Python: Basic Operations
Matlab and Python: Basic OperationsMatlab and Python: Basic Operations
Matlab and Python: Basic Operations
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced python
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
 
Advanced Python, Part 2
Advanced Python, Part 2Advanced Python, Part 2
Advanced Python, Part 2
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015
 
Kotlin collections
Kotlin collectionsKotlin collections
Kotlin collections
 
Learn python in 20 minutes
Learn python in 20 minutesLearn python in 20 minutes
Learn python in 20 minutes
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
 
Argparse: Python command line parser
Argparse: Python command line parserArgparse: Python command line parser
Argparse: Python command line parser
 

Similar to Alias

Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meetMario Fusco
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
Albert Bifet
 
object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lectures
MSohaib24
 
Taming Asynchronous Transforms with Interstellar
Taming Asynchronous Transforms with InterstellarTaming Asynchronous Transforms with Interstellar
Taming Asynchronous Transforms with Interstellar
Jens Ravens
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
BG Java EE Course
 
Porque aprender haskell me fez um programador python melhor?
Porque aprender haskell me fez um programador python melhor?Porque aprender haskell me fez um programador python melhor?
Porque aprender haskell me fez um programador python melhor?UFPA
 
Queue
QueueQueue
Python for Dummies
Python for DummiesPython for Dummies
Python for Dummies
Leonardo Jimenez
 
UNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeUNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllege
Ramanamurthy Banda
 
UNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeUNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllege
Ramanamurthy Banda
 
Lec3
Lec3Lec3
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
Corrado Santoro
 
CSE680-07QuickSort.pptx
CSE680-07QuickSort.pptxCSE680-07QuickSort.pptx
CSE680-07QuickSort.pptx
DeepakM509554
 
Otter 2016-11-28-01-ss
Otter 2016-11-28-01-ssOtter 2016-11-28-01-ss
Otter 2016-11-28-01-ss
Ruo Ando
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programming
Lukasz Dynowski
 
Topic20Arrays_Part2.ppt
Topic20Arrays_Part2.pptTopic20Arrays_Part2.ppt
Topic20Arrays_Part2.ppt
adityavarte
 
MATHEMATICAL MODELING OF COMPLEX REDUNDANT SYSTEM UNDER HEAD-OF-LINE REPAIR
MATHEMATICAL MODELING OF COMPLEX REDUNDANT SYSTEM UNDER HEAD-OF-LINE REPAIRMATHEMATICAL MODELING OF COMPLEX REDUNDANT SYSTEM UNDER HEAD-OF-LINE REPAIR
MATHEMATICAL MODELING OF COMPLEX REDUNDANT SYSTEM UNDER HEAD-OF-LINE REPAIR
Editor IJMTER
 
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUsing-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptx
UadAccount
 
A Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIOA Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIO
Jorge Vásquez
 
OTTER 2017-12-03
OTTER 2017-12-03OTTER 2017-12-03
OTTER 2017-12-03
Ruo Ando
 

Similar to Alias (20)

Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lectures
 
Taming Asynchronous Transforms with Interstellar
Taming Asynchronous Transforms with InterstellarTaming Asynchronous Transforms with Interstellar
Taming Asynchronous Transforms with Interstellar
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
 
Porque aprender haskell me fez um programador python melhor?
Porque aprender haskell me fez um programador python melhor?Porque aprender haskell me fez um programador python melhor?
Porque aprender haskell me fez um programador python melhor?
 
Queue
QueueQueue
Queue
 
Python for Dummies
Python for DummiesPython for Dummies
Python for Dummies
 
UNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeUNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllege
 
UNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllegeUNIT III_Python Programming_aditya COllege
UNIT III_Python Programming_aditya COllege
 
Lec3
Lec3Lec3
Lec3
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
 
CSE680-07QuickSort.pptx
CSE680-07QuickSort.pptxCSE680-07QuickSort.pptx
CSE680-07QuickSort.pptx
 
Otter 2016-11-28-01-ss
Otter 2016-11-28-01-ssOtter 2016-11-28-01-ss
Otter 2016-11-28-01-ss
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programming
 
Topic20Arrays_Part2.ppt
Topic20Arrays_Part2.pptTopic20Arrays_Part2.ppt
Topic20Arrays_Part2.ppt
 
MATHEMATICAL MODELING OF COMPLEX REDUNDANT SYSTEM UNDER HEAD-OF-LINE REPAIR
MATHEMATICAL MODELING OF COMPLEX REDUNDANT SYSTEM UNDER HEAD-OF-LINE REPAIRMATHEMATICAL MODELING OF COMPLEX REDUNDANT SYSTEM UNDER HEAD-OF-LINE REPAIR
MATHEMATICAL MODELING OF COMPLEX REDUNDANT SYSTEM UNDER HEAD-OF-LINE REPAIR
 
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUsing-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptx
 
A Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIOA Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIO
 
OTTER 2017-12-03
OTTER 2017-12-03OTTER 2017-12-03
OTTER 2017-12-03
 

Recently uploaded

Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 

Alias

  • 1. Python Aliasing Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information.
  • 2. An alias is a second name for a piece of data Python Aliasing
  • 3. An alias is a second name for a piece of data Often easier (and more useful) than making a sseeccoonndd ccooppyy Python Aliasing
  • 4. An alias is a second name for a piece of data Often easier (and more useful) than making a sseeccoonndd ccooppyy If the data is immutable, aliases don't matter Python Aliasing
  • 5. An alias is a second name for a piece of data Often easier (and more useful) than making a sseeccoonndd ccooppyy If the data is immutable, aliases don't matter Because the data can't change Python Aliasing
  • 6. An alias is a second name for a piece of data Often easier (and more useful) than making a sseeccoonndd ccooppyy If the data is immutable, aliases don't matter Because the data can't change But if data can change, aliases can result in a lot of hard-to-find bugs Python Aliasing
  • 7. Aliasing happens whenever one variable's value is assigned to another variable Python Aliasing
  • 8. Aliasing happens whenever one variable's value is assigned to another variable first = 'isaac' vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee first 'isaac' Python Aliasing
  • 9. Aliasing happens whenever one variable's value is assigned to another variable first = 'isaac' second = first vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee first second 'isaac' Python Aliasing
  • 10. Aliasing happens whenever one variable's value is assigned to another variable first = 'isaac' second = first But as we've already seen… vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee first second 'isaac' Python Aliasing
  • 11. Aliasing happens whenever one variable's value is assigned to another variable first = 'isaac' second = first But as we've already seen… vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee first = first + ' newton' first second 'isaac' 'isaac newton' Python Aliasing
  • 12. But lists are mutable Python Aliasing
  • 13. But lists are mutable first = ['isaac'] vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee first 'isaac' Python Aliasing
  • 14. But lists are mutable first = ['isaac'] second = first vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee first second 'isaac' Python Aliasing
  • 15. But lists are mutable first = ['isaac'] second = first first = first.append('newton') pppprrrriiiinnnntttt first ['isaac', 'newton'] vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee first second 'isaac' 'newton' Python Aliasing
  • 16. But lists are mutable first = ['isaac'] second = first first = first.append('newton') pppprrrriiiinnnntttt first ['isaac', 'newton'] pppprrrriiiinnnntttt second ['isaac', 'newton'] vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee first second 'isaac' 'newton' Python Aliasing
  • 17. But lists are mutable first = ['isaac'] second = first first = first.append('newton') pppprrrriiiinnnntttt first ['isaac', 'newton'] pppprrrriiiinnnntttt second ['isaac', 'newton'] vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee first Didn't explicitly second 'isaac' 'newton' modify second Python Aliasing
  • 18. But lists are mutable first = ['isaac'] second = first first = first.append('newton') pppprrrriiiinnnntttt first ['isaac', 'newton'] pppprrrriiiinnnntttt second ['isaac', 'newton'] vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee first Didn't explicitly second 'isaac' 'newton' modify second A side effect Python Aliasing
  • 19. Example: use lists of lists to implement a 2D grid Python Aliasing
  • 20. 3 5 Example: use lists of lists to implement a 2D grid 7 2 6 5 7 5 8 5 6 3 3 2 4 4 3 8 Python Aliasing
  • 21. 3 5 Example: use lists of lists to implement a 2D grid 7 2 6 5 7 5 8 5 6 3 3 2 4 grid 4 3 8 Python Aliasing
  • 22. 3 5 Example: use lists of lists to implement a 2D grid 7 2 6 5 7 5 8 5 6 3 3 2 4 grid[0] 4 3 8 Python Aliasing
  • 23. 3 5 Example: use lists of lists to implement a 2D grid 7 2 6 5 7 5 8 5 6 3 3 2 4 grid[0][1] 4 3 8 Python Aliasing
  • 24. # Correct code grid = [] ffffoooorrrr x iiiinnnn range(N): temp = [] ffffoooorrrr y iiiinnnn range(N): temp.append(1) grid.append(temp) Python Aliasing
  • 25. # Correct code grid = [] ffffoooorrrr x iiiinnnn range(N): temp = [] Outer "spine" of structure ffffoooorrrr y iiiinnnn range(N): temp.append(1) grid.append(temp) Python Aliasing
  • 26. # Correct code grid = [] ffffoooorrrr x iiiinnnn range(N): temp = [] ffffoooorrrr y iiiinnnn range(N): temp.append(1) grid.append(temp) Add N sub-lists to outer list Python Aliasing
  • 27. # Correct code grid = [] ffffoooorrrr x iiiinnnn range(N): temp = [] ffffoooorrrr y iiiinnnn range(N): temp.append(1) grid.append(temp) Create a sublist of N 1's Python Aliasing
  • 28. # Equivalent code grid = [] ffffoooorrrr x iiiinnnn range(N): grid.append([]) ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) Python Aliasing
  • 29. # Equivalent code grid = [] ffffoooorrrr x iiiinnnn range(N): grid.append([]) ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) Last element of outer list is the sublist currently being filled in Python Aliasing
  • 30. # Incorrect code grid = [] EMPTY = [] ffffoooorrrr x iiiinnnn range(N): grid.append(EMPTY) ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) Python Aliasing
  • 31. # Incorrect code grid = [] EMPTY = [] ffffoooorrrr x iiiinnnn range(N): # Equivalent code grid = [] ffffoooorrrr x iiiinnnn range(N): grid.append(EMPTY) ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) grid.append([]) ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) Python Aliasing
  • 32. # Incorrect code grid = [] EMPTY = [] ffffoooorrrr x iiiinnnn range(N): Aren't meaningful variable names supposed to be grid.append(EMPTY) ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) a good thing? Python Aliasing
  • 33. vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee grid = [] EMPTY = [] ffffoooorrrr x iiiinnnn range(N): x 0 grid.append(EMPTY) ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) grid EMPTY Python Aliasing
  • 34. vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee grid = [] EMPTY = [] ffffoooorrrr x iiiinnnn range(N): x 0 grid.append(EMPTY) ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) grid EMPTY Python Aliasing
  • 35. vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee grid = [] EMPTY = [] ffffoooorrrr x iiiinnnn range(N): x y 0 0 grid.append(EMPTY) ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) grid EMPTY Python Aliasing
  • 36. vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee grid = [] EMPTY = [] ffffoooorrrr x iiiinnnn range(N): x y 0 0 grid.append(EMPTY) ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) grid EMPTY 1 Python Aliasing
  • 37. vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee grid = [] EMPTY = [] ffffoooorrrr x iiiinnnn range(N): x y 0 2 grid.append(EMPTY) ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) grid EMPTY 1 1 1 Python Aliasing
  • 38. vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee grid = [] EMPTY = [] ffffoooorrrr x iiiinnnn range(N): x y 1 2 grid.append(EMPTY) ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) grid EMPTY 1 1 1 Python Aliasing
  • 39. vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee grid = [] EMPTY = [] ffffoooorrrr x iiiinnnn range(N): x y 1 2 grid.append(EMPTY) ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) grid EMPTY 1 1 1 You see the problem... Python Aliasing
  • 40. No Aliasing ffiirrsstt == [[]] second = [] Python Aliasing
  • 41. No Aliasing Aliasing ffiirrsstt == [[]] ffiirrsstt == [[]] second = [] second = first Python Aliasing
  • 42. vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee grid = [] ffffoooorrrr x iiiinnnn range(N): grid.append([]) x 0 ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) grid Python Aliasing
  • 43. vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee grid = [] ffffoooorrrr x iiiinnnn range(N): grid.append([]) x 0 ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) grid Python Aliasing
  • 44. vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee grid = [] ffffoooorrrr x iiiinnnn range(N): grid.append([]) x y 0 2 ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) grid 1 1 1 Python Aliasing
  • 45. vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee grid = [] ffffoooorrrr x iiiinnnn range(N): grid.append([]) x y 1 2 ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) grid 1 1 1 Python Aliasing
  • 46. vvvvaaaarrrriiiiaaaabbbblllleeee vvvvaaaalllluuuueeee grid = [] ffffoooorrrr x iiiinnnn range(N): grid.append([]) x y 1 0 ffffoooorrrr y iiiinnnn range(N): grid[-1].append(1) grid 1 1 1 1 Python Aliasing
  • 47. If aliasing can cause bugs, why allow it? Python Aliasing
  • 48. If aliasing can cause bugs, why allow it? 1. Some languages don't Python Aliasing
  • 49. If aliasing can cause bugs, why allow it? 1. Some languages don't Or at lleeaasstt aappppeeaarr nnoott ttoo Python Aliasing
  • 50. If aliasing can cause bugs, why allow it? 1. Some languages don't Or at lleeaasstt aappppeeaarr nnoott ttoo 2. Aliasing a million-element list is more efficient than copying it Python Aliasing
  • 51. If aliasing can cause bugs, why allow it? 1. Some languages don't Or at lleeaasstt aappppeeaarr nnoott ttoo 2. Aliasing a million-element list is more efficient than copying it 3. Sometimes really do want to update a structure in place Python Aliasing
  • 52. created by Greg Wilson October 2010 Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information.