the parameter passed in is actually a reference to an object (but the reference is passed by value)

some data types are mutable, but others aren’t

So:

If you pass a mutable object into a method, the method gets a reference to that same object and you can mutate it to your heart’s delight, but if you rebind the reference in the method, the outer scope will know nothing about it, and after you’re done, the outer reference will still point at the original object.

If you pass an immutable object to a method, you still can’t rebind the outer reference, and you can’t even mutate the object.

Since the the_list parameter was passed by value, assigning a new list to it had no effect that the code outside the method could see. The the_list was a copy of the outer_list reference, and we had the_list point to a new list, but there was no way to change where outer_listpointed.

String – an immutable type

It’s immutable, so there’s nothing we can do to change the contents of the string

Now, let’s try to change the reference

def try_to_change_string_reference(the_string):print('got', the_string)
the_string ='In a kingdom by the sea'print('set to', the_string)
outer_string ='It was many and many a year ago'print('before, outer_string =', outer_string)
try_to_change_string_reference(outer_string)print('after, outer_string =', outer_string)

Output:

before, outer_string = It was many and many a year ago
got It was many and many a year ago
set to In a kingdom by the sea
after, outer_string = It was many and many a year ago

Again, since the the_string parameter was passed by value, assigning a new string to it had no effect that the code outside the method could see. The the_string was a copy of the outer_string reference, and we had the_string point to a new string, but there was no way to change where outer_string pointed.

I hope this clears things up a little.

EDIT: It’s been noted that this doesn’t answer the question that @David originally asked, “Is there something I can do to pass the variable by actual reference?”. Let’s work on that.

How do we get around this?

As @Andrea’s answer shows, you could return the new value. This doesn’t change the way things are passed in, but does let you get the information you want back out:

def return_a_whole_new_string(the_string):
new_string = something_to_do_with_the_old_string(the_string)return new_string
# then you could call it like
my_string = return_a_whole_new_string(my_string)

If you really wanted to avoid using a return value, you could create a class to hold your value and pass it into the function or use an existing class, like a list:

You might need to install libpng12-0 if you haven’t installed already. You can follow the instructions described here, for 64-bit or 32-bit systems. But, all you have to do is to edit your source.list and then, you should add:

ARP requests are never forwarded to reach the end host in IP-routed networks. [original post]

“There will never be an ARP request from “the internet” asking about the address for one of your hosts. IP addresses are used for end-to-end routing. Hardware addresses are used only for single hops. So if some host on the internet sends a ping, every router along the way will look at the destination IP address, consult its routing table for the next hop (IP address) in the right direction, and send the packet to the next hop host or router. To do that very last step (forward the packet to the next hop), the router needs to know the hardware address of the next hop. But it does not need to know the hardware address of the destination host. This means that arp requests are never forwarded. They are only generated for IP addresses that are directly attached to the router that is sending the request. So no router except yours will ever send an arp request for the hosts that are serviced by your router.”

ARP request for address 0.0.0.0 means that each host which receives the request must reply. [original post]

“The address ‘0.0.0.0’ is the ‘any’ address. That means, ‘any’ host should answer that request.”