Skip to Content
Perl To Python Migration
book

Perl To Python Migration

by Martin C. Brown
November 2001
Beginner
320 pages
5h 53m
English
Pearson Business
Content preview from Perl To Python Migration

COPYING VARIABLES

One of the problems with Python using references to data all of the time is that it can play havoc with data structures which are using references, rather than copies of data from other variables. For example, the following fragment creates two variables, alist and blist:

>>> alist = [25,50,75,100]
>>> blist = alist

The blist variable is a reference to the same array object as alist, which means changing a value in the variable alist modifies the same list to which blist points, such that:

>>> alist[3] = 2000
>>> alist
[25, 50, 75, 2000]
>>> blist
[25, 50, 75, 2000]
>>>

We get the same value – both alist and blist point to the same array, so modifying values in one modifies the values we get back from the other.

To make ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl in a Nutshell

Perl in a Nutshell

Nathan Patwardhan, Ellen Siever, Stephen Spainhour
Perl by Example

Perl by Example

Ellie Quigley
Perl Hacks

Perl Hacks

Chromatic, Damian Conway, Curtis Ovid Poe, Curtis (Ovid) Poe

Publisher Resources

ISBN: 0201734885Purchase book