A certainl part of an if() structure never gets executed.

Nick the Gr33k support at superhost.gr
Sun Jun 16 04:07:12 EDT 2013


On 16/6/2013 9:32 πμ, Denis McMahon wrote:
> On Sat, 15 Jun 2013 19:18:53 +0300, Nick the Gr33k wrote:
>
>> In both situations we still have 2 memory units holding values, so hows
>> that different?
>
> Consider that each named variable is a pointer to a memory location that
> holds a value. This is one of the ways in that a typed compiled language
> and an untyped scripted language may differ in their treatment of data
> items (or variables).
>
> Consider the following C and Python code:
>
> C:
>
> int a, b;
> b = 6;
> a = b;
>
> In C, this places the numeric value 6 into the memory location identified
> by the variable "b", then copies the value from the location pointed to
> by "b" into the location pointed to by "a".
>
> b is a pointer to a memory location containing the value 6
> a is a pointer to another memory location also containing the value 6
>
> Python:
>
> b = 6
> a = b
>
> In Python, this first puts the value 6 in in a memory location and points
> "b" at that memory location, then makes "a" point to the same memory
> location as "b" points to.
>
> b is a pointer to a memory location containing the value 6
> a is a pointer to the same memory location
>
> Do you understand the difference?
>
Yes and thank you for explaining in detail to me.
So Python economies(saves) system's memory. Good job Python!

There is no point having 2 variables point to 2 different memory 
locations as C does since both of those memory locations are supposed to 
contain the same value!

One thing that i want you guys to confirm to me:

a and b in both of the languages mentioned are pointers to memory 
locations which hold a value.

A pointer = a variable that has as a value a memory address
a variable = a memory address that has as a value the actual value we 
want to store.

But since pointer itself is a memory location that holds as a value the 
address of another memory location(by definition) that in it's own turn 
holds the actual value we want stored?

So the scheme would look like this in Python:

memory address = number 6

memory address = memory address value that stores number 6 (pointer a)

memory address = memory address value that stores number 6 (pointer b)


So having in mind the above.

The memory address that actually stores number 6 have no name at all and 
the only way to access it's value is by printing the variables a or b? 
Doesn't that memory address have a name itself?

if someone wants the memory address of the pointer's a or b, how can he 
access it? in C it was somethign like &a and &b

And in Python internally shall i imagine two tables that has 
associations of:

variable's_name <-> memory_address <-> actual value

And ALL 3 of them are actually bits(1s and 0s)

Is this how the thing works?

-- 
What is now proved was at first only imagined!



More information about the Python-list mailing list