Last active
June 20, 2020 23:23
-
-
Save vchan14/a81348127b17f03a4aed3376ffd12fa6 to your computer and use it in GitHub Desktop.
Mutable vs Immutable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def addTwo(val): | |
val += 2 | |
x = 1 | |
addTwo(x) | |
print(x) | |
# Output 1 | |
# Expected 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
favoriteNumbers = [1, 2, 3, 4] | |
# Update the first element to 0 | |
favoriteNumbers[0] = 0 | |
# Add 5 to the list | |
favoriteNumbers += [5] | |
print(favoriteNumber) | |
# Output [0, 2, 3, 4, 5] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment