Skip to content
Permalink
7ae7d3de3a
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
30 lines (26 sloc) 524 Bytes
#!/usr/bin/env python3
# example-2.py
# showing pass by reference
var = 20
print("Initial variable value and object number:")
print(var)
print(id(var))
def pass_by_reference():
global var
print("Initial ")
print(id(var))
var += 20
print(var)
print(id(var))
pass_by_reference()
print(var)
print(id(var))
def pass_by_value(var):
total = var
total = total + 20
print(total)
print(id(total))
return total
pass_by_value(var)
print(var)
print(id(var))