Some python basics


def assign_value(n, v):
print(“address of n {}”.format(id(n))) n = v print(“address of n {}”.format(id(n)))
list1 = [1, 2, 3]list2 = [4, 5, 6]list3 = list1[:] list4 = list1 assign_value(list1, list2)print(list1)print(“address of list1 {}”.format(id(list1)))print(“address of list3 {}”.format(id(list3)))print(“address of list4 {}”.format(id(list4)))
list = list + [“a”] # not in-placelist += [“a”] # in-place
# inta = 1
b = 1
print(id(a))
print(id(b))
a = a + 1
print(id(a))
a = 2
print(id(a))
# list a = [1]
b = [1]
print(id(a))
print(id(b))
a = [2]
print(id(a))

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store