SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 292 | Next

Shon Harris, Allen Harper, Chris Eagle, and Jonathan Ness

"Gray Hat Hacking, Second Edition"

The syntax is simple and straightforward, just as you??™ll come to expect from
Python. One important distinction to make right away is that each of those strings (we
named themstring1, string2, and string3) is simply a pointer??”forthose familiar with
C??”or a label for a blob of data out in memory someplace. One concept that sometimes
trips up new programmers is the idea of one label (or pointer) pointing to another label.
The following code and Figure 6-1 demonstrate this concept:
>>> label1 = 'Dilbert'
>>> label2 = label1
At this point, we have a blob of memory somewhere with the Python string ???Dilbert??™
stored. We also have two labels pointing at that blob of memory.
Chapter 6: Programming Survival Skills
141
PART III
Figure 6-1
Two labels pointing at the
same string in memory
If we then change label1??™s assignment, label2 does not change.
... continued from above
>>> label1 = 'Dogbert'
>>> label2
'Dilbert'
As you see in Figure 6-2, label2 is not pointing to label1, per se. Rather, it??™s pointing to
the same thing label1 was pointing to until label1 was reassigned.
Numbers
Similar to Python strings, numbers point to an object that can contain any kind of number.
It will hold small numbers, big numbers, complex numbers, negative numbers, and
any other kind of number you could dream up.


Pages:
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304